On 7/23/07, arifin <niazarifin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
>
> Hi,
> I have a form with a text_field in one of my views in RAILS. I need to:
>
> 1. put a ''reset'' button so that I can clear (set to
blank) the text_field
> when the user clicks on the button
<% form_tag(site_search_path, {:name => ''search_form''})
do -%>
<%= text_field_tag(''search_string'', @search_string) %>
<%= submit_tag(''Search'') %>
<%= submit_tag("Reset Form", :onclick =>
"document.search_form.reset();" ) %>
<% end %>
the above will display a "Reset Form" button which will reset all the
field values in your form.
> 2. retain value in text_field: I have a ''search'' button
that performs search
> (not Ajax livesearch... it''s a simple search and I wrote the code
in my
> controller). Now, when the user puts some text (query) in the text_field
and
> clicks on ''search'', the results are shown ok, but I need
to retain the text
> in the text-field that the user put in. Also I need to set the focus to
this
> text_field after the results are shown.
you''ll have to store the search params in an ivar in your controller,
and then repopulate them into the search form using text_field_tag
like I did above with "text_field_tag(''search_string'',
@search_string)" which will fill in the text field with whatever value
is stored in @search_string.
>
> The relevant code in the view is:
> <%= start_form_tag :action => ''search''%>
> <%= text_field :server, :server_name, :size => 15 %>
> <%= submit_tag ''Search'' %>
> <%= end_form_tag %>
> <%= set_focus_to_id ''server_server_name'' %>
don''t use start_form_tag or end_form_tag, they''ve been
deprecated.
Adam
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---