diff options
author | Robin Houston <robin@lenny.robin> | 2011-09-08 01:21:08 +0100 |
---|---|---|
committer | Robin Houston <robin@lenny.robin> | 2011-09-08 01:21:08 +0100 |
commit | 723505344edc7af189b23ffcf9cd033f19727436 (patch) | |
tree | c8ee4a5821d4cff9592a83c09ffd1a8a38b1b2c6 | |
parent | 0b35486809a9a5ef8ba371549b05390682427392 (diff) |
Make HTML ids unique even with multiple locales
In situations where a block of HTML is generated for each enabled locale,
we need to include the locale name in generated ids otherwise the id will
not be unique within the document, resulting in invalid HTML.
-rw-r--r-- | app/helpers/application_helper.rb | 8 | ||||
-rw-r--r-- | app/views/admin_public_body/_form.rhtml | 20 |
2 files changed, 16 insertions, 12 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d12238582..a0f16dfaf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -105,8 +105,12 @@ module ApplicationHelper method_name.sub(/\?$/, "") end - def form_tag_id(object_name, method_name) - return "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" + def form_tag_id(object_name, method_name, locale=nil) + if locale.nil? + return "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" + else + return "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}__#{locale.to_s}" + end end end diff --git a/app/views/admin_public_body/_form.rhtml b/app/views/admin_public_body/_form.rhtml index 6a9013071..1cdc9b3fe 100644 --- a/app/views/admin_public_body/_form.rhtml +++ b/app/views/admin_public_body/_form.rhtml @@ -26,20 +26,20 @@ <div id="div-locale-<%=locale.to_s%>"> <%= t.hidden_field :locale, :value => locale.to_s %> - <p><label for="<%= form_tag_id(t.object_name, :name) %>">Name</label><br/> - <%= t.text_field :name, :size => 60, :id => form_tag_id(t.object_name, :name) %></p> + <p><label for="<%= form_tag_id(t.object_name, :name, locale) %>">Name</label><br/> + <%= t.text_field :name, :size => 60, :id => form_tag_id(t.object_name, :name, locale) %></p> - <p><label for="<%= form_tag_id(t.object_name, :short_name) %>">Short name <small>(only put in abbreviations which are really used, otherwise leave blank. Short or long name is used in the URL - don't worry about breaking URLs through renaming, as the history is used to redirect)</small></label><br/> - <%= t.text_field :short_name, :size => 60, :id => form_tag_id(t.object_name, :short_name) %></p> + <p><label for="<%= form_tag_id(t.object_name, :short_name, locale) %>">Short name <small>(only put in abbreviations which are really used, otherwise leave blank. Short or long name is used in the URL - don't worry about breaking URLs through renaming, as the history is used to redirect)</small></label><br/> + <%= t.text_field :short_name, :size => 60, :id => form_tag_id(t.object_name, :short_name, locale) %></p> - <p><label for="<%= form_tag_id(t.object_name, :request_email) %>">Request email <small>(set to <strong>blank</strong> (empty string) if can't find an address; these emails are <strong>public</strong> as anyone can view with a CAPTCHA)</small></label><br/> - <%= t.text_field :request_email, :size => 40, :id => form_tag_id(t.object_name, :request_email) %></p> + <p><label for="<%= form_tag_id(t.object_name, :request_email, locale) %>">Request email <small>(set to <strong>blank</strong> (empty string) if can't find an address; these emails are <strong>public</strong> as anyone can view with a CAPTCHA)</small></label><br/> + <%= t.text_field :request_email, :size => 40, :id => form_tag_id(t.object_name, :request_email, locale) %></p> - <p><label for="<%= form_tag_id(t.object_name, :publication_scheme) %>">Publication scheme URL</label><br/> - <%= t.text_field :publication_scheme, :size => 60, :id => form_tag_id(t.object_name, :publication_scheme) %></p> + <p><label for="<%= form_tag_id(t.object_name, :publication_scheme, locale) %>">Publication scheme URL</label><br/> + <%= t.text_field :publication_scheme, :size => 60, :id => form_tag_id(t.object_name, :publication_scheme, locale) %></p> - <p><label for="<%= form_tag_id(t.object_name, :notes) %>">Public notes</label> <small>(HTML, for users to consider when making FOI requests to the authority)</small><br/> - <%= t.text_area :notes, :rows => 3, :cols => 60, :id => form_tag_id(t.object_name, :notes) %></p> + <p><label for="<%= form_tag_id(t.object_name, :notes, locale) %>">Public notes</label> <small>(HTML, for users to consider when making FOI requests to the authority)</small><br/> + <%= t.text_area :notes, :rows => 3, :cols => 60, :id => form_tag_id(t.object_name, :notes, locale) %></p> </div> <% end |