Hello! I have a systemwide search field with a submit button (submit_tag). Like so: <%= submit_tag "Search" %> I wonder if there is a way to link to a chosen path when the user presses the submit button, in my case to the root_path. Or should i use something else instead of ''submit_tag''? I have another question on a similar topic, in my search field I have a default text value (:value => "Search on..."), is there an easy Rails way to clear the default value when the user activates the field, or should I use some Javascript? Examples or links would greatly be appreciated. Thanks // Anders -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The link that a form submits to is set in the form tag itself, not the button. Here''s what I mean: <% form_tag documents_path, :method => ''get'' do %> <div id="search"> <%= link_to("Show All") if params[:q] %> <%= text_field_tag :q, params[:q] %> <%= submit_tag "Search", :name => nil, :id => ''search_submit'' %> </div> <% end %> Walter On Oct 3, 2010, at 8:33 AM, Anders_P wrote:> Hello! > > I have a systemwide search field with a submit button (submit_tag). > Like so: > > <%= submit_tag "Search" %> > > I wonder if there is a way to link to a chosen path when the user > presses the submit button, in my case to the root_path. Or should i > use something else instead of ''submit_tag''? > > I have another question on a similar topic, in my search field I have > a default text value (:value => "Search on..."), is there an easy > Rails way to clear the default value when the user activates the > field, or should I use some Javascript? > > Examples or links would greatly be appreciated. > > Thanks > > // Anders > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 > . >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks a lot! That worked. Do you have any tips on my second question? Anders On 3 Okt, 16:15, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> The link that a form submits to is set in the form tag itself, not the > button. Here''s what I mean: > > <% form_tag documents_path, :method => ''get'' do %> > <div id="search"> > <%= link_to("Show All") if params[:q] %> > <%= text_field_tag :q, params[:q] %> > <%= submit_tag "Search", :name => nil, :id => ''search_submit'' %> > </div> > <% end %> > > Walter > > On Oct 3, 2010, at 8:33 AM, Anders_P wrote: > > > > > Hello! > > > I have a systemwide search field with a submit button (submit_tag). > > Like so: > > > <%= submit_tag "Search" %> > > > I wonder if there is a way to link to a chosen path when the user > > presses the submit button, in my case to the root_path. Or should i > > use something else instead of ''submit_tag''? > > > I have another question on a similar topic, in my search field I have > > a default text value (:value => "Search on..."), is there an easy > > Rails way to clear the default value when the user activates the > > field, or should I use some Javascript? > > > Examples or links would greatly be appreciated. > > > Thanks > > > // Anders > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > . > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en > > .-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Here''s a page that explains how to do this using JavaScript within the form builder syntax. http://www.folksonomy.org/2008/12/22/rails-auto-clearing-input-field/ Note that any element like this will rely on JavaScript on the client to keep from submitting the default value. Be sure to check in your controller for that explicit value and ignore the search event in that case. Walter On Oct 3, 2010, at 12:18 PM, Anders_P wrote:> Thanks a lot! That worked. > > Do you have any tips on my second question? > > Anders-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks it worked. On 3 Okt, 18:31, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> Here''s a page that explains how to do this using JavaScript within the > form builder syntax. > > http://www.folksonomy.org/2008/12/22/rails-auto-clearing-input-field/ > > Note that any element like this will rely on JavaScript on the client > to keep from submitting the default value. Be sure to check in your > controller for that explicit value and ignore the search event in that > case. > > Walter > > On Oct 3, 2010, at 12:18 PM, Anders_P wrote: > > > > > Thanks a lot! That worked. > > > Do you have any tips on my second question? > > > Anders-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.