ct9a
March 17, 2010, 4:45am
1
hi, guys,
I have an app which has two forms on the page.
Both forms are based on a “search” model.
Search by keyword only (hence, only 1 element being “keyword”)
Search by a few different attributes (including keyword).
Attributes are such as price, brand and make.
When constructing a search form, “form_for” will be used. Here’s an
extract from one of them:
-------------------- Extract start
<% form_for :search, :url => search_path, :html => {:method => “get”}
do |f| %>
<%= render :partial => 'search/categories' %>
<%= f.label :title_like, "Brand" %>
<%= f.text_field :brand_like %>
…
<%= f.label :title_like, "Keyword" %>
<%= f.text_field :title_like %>
<%= f.submit 'Search' %>
<% end %>
-------------------- Extract end
-------------------------------------------------------------------------------------
Now, when the page loads, there are two search forms and both of them
will have submit buttons with identical names being “search_submit”.
This will obviously cause a failure in the w3c html validator due to
the identical elements appearing more than once in a page.
Is there any way we can specify the name of a given submit button?
Is there an alternative such that I can still maintain two search
forms in the same page?
thank you.
ct9a
March 17, 2010, 4:52am
2
On Tue, 2010-03-16 at 20:44 -0700, ct9a wrote:
extract from one of them:
-------------------- Extract end
2) Is there an alternative such that I can still maintain two search
forms in the same page?
f.submit ‘Search Categories’
f.submit ‘Search Something Else’
Craig
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
ct9a
March 17, 2010, 4:56am
3
Thanks craig but my mistake, guys.
I meant the “id” attribute.
Hence, we’ll get two submit buttons:
(first form)
(second form)
ct9a
March 17, 2010, 5:14am
4
Gordon Y. wrote:
Thanks craig but my mistake, guys.
I meant the “id” attribute.
Hence, we’ll get two submit buttons:
(first form)
(second form)
Dear friend,
Why can't use "submit_tag" in both partial and in the current
form ? While using it , it won’t have this id attribute.
ct9a
March 17, 2010, 5:17am
5
Smart idea! thank you. I will try it out and revert.
Cheers!
ct9a
March 17, 2010, 5:07am
6
On Wed, 2010-03-17 at 14:54 +1100, Gordon Y. wrote:
> I have an app which has two forms on the page.
> -------------------- Extract start
> <%= f.text_field :brand_like %>
> <% end %>
> This will obviously cause a failure in the w3c html
----
f.submit 'Search Categories'
f.submit 'Search Something Else'
untested but I think should work but I got the impression that the ‘id’
if not specified would dynamically pick from the action and the name.
<% form_for :search, :url => search_path, :html => {:method =>
“get”, :id => “something”} do |f| %>
Craig
–
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
ct9a
March 17, 2010, 10:13am
7
On 17 March 2010 03:54, Gordon Y. [email protected] wrote:
(second form)
I can confirm that
<%= f.submit “Search”, :id => “a_search” %>
<%= f.submit “Search”, :id => “another_search” %>
will give different id’s and so keep the html valid
Colin
ct9a
March 17, 2010, 5:42am
8
Problem solved. Thanks, Loganathan .
W3C html validator is happy with the output generated.
ct9a
March 17, 2010, 11:28am
9
bravo.
another brilliant reply