From 3ea9f3cecf7c7f3547444fe85c1aa55ca82399fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 2 Oct 2019 23:27:48 +0200 Subject: [PATCH 1/8] Simplify generating form fields with labels Instead of generating the label and then a field without a label, we can directly generate a field with a label. --- app/helpers/documents_helper.rb | 21 +++++------ app/helpers/images_helper.rb | 22 +++++------- app/views/admin/banners/_form.html.erb | 9 ++--- .../admin/budget_investments/edit.html.erb | 3 +- app/views/admin/budget_phases/_form.html.erb | 6 ++-- .../admin/dashboard/actions/_form.html.erb | 12 +++---- .../legislation/draft_versions/_form.html.erb | 6 ++-- .../admin/local_census_records/_form.html.erb | 13 +++---- app/views/admin/newsletters/_form.html.erb | 3 +- app/views/admin/poll/shifts/_form.html.erb | 4 +-- .../_form_content_block.html.erb | 9 ++--- .../site_customization/pages/_form.html.erb | 4 +-- app/views/admin/tags/index.html.erb | 3 +- app/views/admin/valuator_groups/edit.html.erb | 3 +- app/views/admin/valuator_groups/new.html.erb | 3 +- app/views/budgets/investments/_form.html.erb | 3 +- app/views/comments/_form.html.erb | 8 +++-- .../devise/password_expired/show.html.erb | 5 +-- app/views/direct_messages/new.html.erb | 7 ++-- .../legislation/proposals/_form.html.erb | 16 +++++---- app/views/management/users/new.html.erb | 3 +- app/views/proposal_notifications/new.html.erb | 8 ++--- app/views/proposals/_form.html.erb | 4 +-- app/views/proposals/retire_form.html.erb | 5 +-- app/views/shared/_map.html.erb | 3 +- app/views/topics/_form.html.erb | 7 ++-- app/views/tracking/milestones/_form.html.erb | 3 +- app/views/users/registrations/edit.html.erb | 12 ++++--- .../budget_investments/_dossier_form.html.erb | 35 ++++++++++--------- app/views/verification/residence/new.html.erb | 7 ++-- app/views/verification/sms/edit.html.erb | 3 +- 31 files changed, 109 insertions(+), 141 deletions(-) diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index d8de03389..6403bd440 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -33,18 +33,15 @@ module DocumentsHelper def render_attachment(builder, document) klass = document.persisted? || document.cached_attachment.present? ? " hide" : "" - html = builder.label :attachment, - t("documents.form.attachment_label"), - class: "button hollow #{klass}" - html += builder.file_field :attachment, - label: false, - accept: accepted_content_types_extensions(document.documentable_type.constantize), - class: "js-document-attachment", - data: { - url: document_direct_upload_url(document), - nested_document: true - } - html + builder.file_field :attachment, + label: t("documents.form.attachment_label"), + label_options: { class: "button hollow #{klass}" }, + accept: accepted_content_types_extensions(document.documentable_type.constantize), + class: "js-document-attachment", + data: { + url: document_direct_upload_url(document), + nested_document: true + } end def document_direct_upload_url(document) diff --git a/app/helpers/images_helper.rb b/app/helpers/images_helper.rb index c865c6937..0fbe1dd2f 100644 --- a/app/helpers/images_helper.rb +++ b/app/helpers/images_helper.rb @@ -47,19 +47,15 @@ module ImagesHelper def render_image_attachment(builder, imageable, image) klass = image.persisted? || image.cached_attachment.present? ? " hide" : "" - html = builder.label :attachment, - t("images.form.attachment_label"), - class: "button hollow #{klass}" - html += builder.file_field :attachment, - label: false, - accept: imageable_accepted_content_types_extensions, - class: "js-image-attachment", - data: { - url: image_direct_upload_url(imageable), - nested_image: true - } - - html + builder.file_field :attachment, + label: t("images.form.attachment_label"), + label_options: { class: "button hollow #{klass}" }, + accept: imageable_accepted_content_types_extensions, + class: "js-image-attachment", + data: { + url: image_direct_upload_url(imageable), + nested_image: true + } end def render_image(image, version, show_caption = true) diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb index 0195d8e52..5e7d6e56b 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/views/admin/banners/_form.html.erb @@ -7,9 +7,8 @@
<% date_started_at = @banner.post_started_at.present? ? I18n.localize(@banner.post_started_at) : "" %>
- <%= f.label :post_started_at, t("admin.banners.banner.post_started_at") %> <%= f.text_field :post_started_at, - label: false, + label: t("admin.banners.banner.post_started_at"), placeholder: t("admin.banners.banner.post_started_at"), value: date_started_at, class: "js-calendar-full", @@ -17,9 +16,8 @@
<% date_ended_at = @banner.post_ended_at.present? ? I18n.localize(@banner.post_ended_at) : "" %>
- <%= f.label :post_ended_at, t("admin.banners.banner.post_ended_at") %> <%= f.text_field :post_ended_at, - label: false, + label: t("admin.banners.banner.post_ended_at"), placeholder: t("admin.banners.banner.post_ended_at"), value: date_ended_at, class: "js-calendar-full", @@ -47,9 +45,8 @@
- <%= f.label :target_url, t("admin.banners.banner.target_url") %> <%= f.text_field :target_url, - label: false, + label: t("admin.banners.banner.target_url"), placeholder: t("admin.banners.banner.target_url") %>
diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index 8051783c7..851b43789 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -29,10 +29,9 @@ <% end %>
- <%= f.label :tag_list, t("admin.budget_investments.edit.user_tags") %> <%= f.text_field :tag_list, value: @investment.tag_list.sort.join(","), - label: false %> + label: t("admin.budget_investments.edit.user_tags") %>
diff --git a/app/views/admin/budget_phases/_form.html.erb b/app/views/admin/budget_phases/_form.html.erb index 4bb746219..8a3e94c4c 100644 --- a/app/views/admin/budget_phases/_form.html.erb +++ b/app/views/admin/budget_phases/_form.html.erb @@ -6,20 +6,18 @@
- <%= f.label :starts_at, t("admin.budget_phases.edit.start_date") %> <%= f.text_field :starts_at, value: format_date_for_calendar_form(@phase.starts_at), class: "js-calendar-full", id: "start_date", - label: false %> + label: t("admin.budget_phases.edit.start_date") %>
- <%= f.label :ends_at, t("admin.budget_phases.edit.end_date") %> <%= f.text_field :ends_at, value: format_date_for_calendar_form(@phase.ends_at), class: "js-calendar-full", id: "end_date", - label: false %> + label: t("admin.budget_phases.edit.end_date") %>
diff --git a/app/views/admin/dashboard/actions/_form.html.erb b/app/views/admin/dashboard/actions/_form.html.erb index 59e74690a..5e7499451 100644 --- a/app/views/admin/dashboard/actions/_form.html.erb +++ b/app/views/admin/dashboard/actions/_form.html.erb @@ -5,9 +5,9 @@ <%= f.label :action_type %> <% ::Dashboard::Action.action_types.keys.each do |action_type_value| %> - <%= f.radio_button :action_type, action_type_value, label: false, - data: { toggle: "request_to_administrators short_description" } %> - <%= f.label "action_type_#{action_type_value}", t("admin.dashboard.actions.action_type.#{action_type_value}") %> + <%= f.radio_button :action_type, action_type_value, + label: t("admin.dashboard.actions.action_type.#{action_type_value}"), + data: { toggle: "request_to_administrators short_description" } %> <% end %>
@@ -26,12 +26,10 @@
- <%= f.label :title %> - <%= f.text_field :title, label: false %> + <%= f.text_field :title %>
- <%= f.label :short_description %> - <%= f.text_field :short_description, label: false %> + <%= f.text_field :short_description %>
diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index d0cf4f317..6e2395ebb 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -71,16 +71,14 @@
<%= f.label :status %> <% ::Legislation::DraftVersion::VALID_STATUSES.each do |status| %> - <%= f.radio_button :status, status, label: false %> - <%= f.label "status_#{status}", t("admin.legislation.draft_versions.statuses.#{status}") %> + <%= f.radio_button :status, status, label: t("admin.legislation.draft_versions.statuses.#{status}") %> <%= t("admin.legislation.draft_versions.form.hints.status.#{status}") %>
<% end %>
- <%= f.label :final_version %> - <%= f.check_box :final_version, label: false %> + <%= f.check_box :final_version %> <%= t("admin.legislation.draft_versions.form.hints.final_version") %>
diff --git a/app/views/admin/local_census_records/_form.html.erb b/app/views/admin/local_census_records/_form.html.erb index 959b365cd..5b1dcd9ea 100644 --- a/app/views/admin/local_census_records/_form.html.erb +++ b/app/views/admin/local_census_records/_form.html.erb @@ -15,17 +15,14 @@
- <%= f.label :date_of_birth, t("admin.local_census_records.form.date_of_birth") %> -
- <%= f.date_select :date_of_birth, - prompt: true, - start_year: 1900, end_year: minimum_required_age.years.ago.year, - label: false %> -
+ <%= f.date_select :date_of_birth, + prompt: true, + start_year: 1900, end_year: minimum_required_age.years.ago.year, + label: t("admin.local_census_records.form.date_of_birth") %>
-
+
<%= f.text_field :postal_code %>
diff --git a/app/views/admin/newsletters/_form.html.erb b/app/views/admin/newsletters/_form.html.erb index 37a153fab..c68d3cb37 100644 --- a/app/views/admin/newsletters/_form.html.erb +++ b/app/views/admin/newsletters/_form.html.erb @@ -4,8 +4,7 @@ <%= f.select :segment_recipient, options_for_select(user_segments_options, @newsletter[:segment_recipient]) %> <%= f.text_field :subject %> - <%= f.label :from, t("admin.newsletters.new.from") %> - <%= f.text_field :from, label: false %> + <%= f.text_field :from, label: t("admin.newsletters.new.from") %> <%= f.cktext_area :body, ckeditor: { language: I18n.locale } %>
diff --git a/app/views/admin/poll/shifts/_form.html.erb b/app/views/admin/poll/shifts/_form.html.erb index 726e0797f..5b0f86e7c 100644 --- a/app/views/admin/poll/shifts/_form.html.erb +++ b/app/views/admin/poll/shifts/_form.html.erb @@ -13,11 +13,9 @@
- <%= f.select :task, Poll::Shift.tasks.map { |k, v| [t("admin.poll_shifts.#{k}"), k] }, - { prompt: t("admin.poll_shifts.new.select_task"), - label: false }, + { prompt: t("admin.poll_shifts.new.select_task"), label: t("admin.poll_shifts.new.task") }, class: "js-poll-shifts" %>
diff --git a/app/views/admin/site_customization/content_blocks/_form_content_block.html.erb b/app/views/admin/site_customization/content_blocks/_form_content_block.html.erb index 897558fe4..0753b075e 100644 --- a/app/views/admin/site_customization/content_blocks/_form_content_block.html.erb +++ b/app/views/admin/site_customization/content_blocks/_form_content_block.html.erb @@ -16,17 +16,14 @@ <% end %>
- <%= f.label :name %> - <%= f.select :name, options_for_select(valid_blocks, @selected_content_block), label: false %> + <%= f.select :name, options_for_select(valid_blocks, @selected_content_block) %>
- <%= f.label :locale %> - <%= f.select :locale, I18n.available_locales, label: false %> + <%= f.select :locale, I18n.available_locales %>
- <%= f.label :body %> - <%= f.text_area :body, label: false, rows: 10 %> + <%= f.text_area :body, rows: 10 %>
<%= f.submit class: "button success expanded" %>
diff --git a/app/views/admin/site_customization/pages/_form.html.erb b/app/views/admin/site_customization/pages/_form.html.erb index c253798d8..dbe602451 100644 --- a/app/views/admin/site_customization/pages/_form.html.erb +++ b/app/views/admin/site_customization/pages/_form.html.erb @@ -22,8 +22,8 @@

<%= t("admin.site_customization.pages.form.options") %>

<%= f.label :status %> <% ::SiteCustomization::Page::VALID_STATUSES.each do |status| %> - <%= f.radio_button :status, status, label: false %> - <%= f.label "status_#{status}", t("admin.site_customization.pages.page.status_#{status}") %> + <%= f.radio_button :status, status, + label: t("admin.site_customization.pages.page.status_#{status}") %>
<% end %> diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb index b02959059..c40c113d0 100644 --- a/app/views/admin/tags/index.html.erb +++ b/app/views/admin/tags/index.html.erb @@ -3,8 +3,7 @@ <%= form_for(@tag, url: admin_tags_path, as: :tag) do |f| %>
- <%= f.label :name, t("admin.tags.name.placeholder") %> - <%= f.text_field :name, placeholder: t("admin.tags.name.placeholder"), label: false %> + <%= f.text_field :name, placeholder: t("admin.tags.name.placeholder"), label: t("admin.tags.name.placeholder") %>
<%= f.submit(t("admin.tags.create"), class: "button success") %> diff --git a/app/views/admin/valuator_groups/edit.html.erb b/app/views/admin/valuator_groups/edit.html.erb index b73095d2e..495750acc 100644 --- a/app/views/admin/valuator_groups/edit.html.erb +++ b/app/views/admin/valuator_groups/edit.html.erb @@ -2,8 +2,7 @@
<%= form_for [:admin, @group] do |f| %> - <%= f.label :name, t("admin.valuator_groups.form.name") %> - <%= f.text_field :name, label: false %> + <%= f.text_field :name, label: t("admin.valuator_groups.form.name") %> <%= f.submit t("admin.valuator_groups.form.edit"), class: "button success" %> <% end %>
diff --git a/app/views/admin/valuator_groups/new.html.erb b/app/views/admin/valuator_groups/new.html.erb index d79f22d85..044c626a7 100644 --- a/app/views/admin/valuator_groups/new.html.erb +++ b/app/views/admin/valuator_groups/new.html.erb @@ -2,8 +2,7 @@
<%= form_for [:admin, @group] do |f| %> - <%= f.label :name, t("admin.valuator_groups.form.name") %> - <%= f.text_field :name, label: false %> + <%= f.text_field :name, label: t("admin.valuator_groups.form.name") %> <%= f.submit t("admin.valuator_groups.form.new"), class: "button success" %> <% end %>
diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index f1b405cc5..4fb08a56b 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -59,8 +59,7 @@ <% end %>
- <%= f.label :location, t("budgets.investments.form.location") %> - <%= f.text_field :location, label: false %> + <%= f.text_field :location, label: t("budgets.investments.form.location") %>
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 4841e6871..9e828bd08 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -3,8 +3,12 @@ <% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
class="comment-form"> <%= form_for Comment.new, remote: true do |f| %> - <%= label_tag "comment-body-#{css_id}", leave_comment_text(commentable) %> - <%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment.body_max_length, label: false %> + <%= f.text_area :body, + id: "comment-body-#{css_id}", + maxlength: Comment.body_max_length, + label: leave_comment_text(commentable), + label_options: { for: "comment-body-#{css_id}" } %> + <%= f.hidden_field :commentable_type, value: commentable.class.name %> <%= f.hidden_field :commentable_id, value: commentable.id %> <%= f.hidden_field :parent_id, value: parent_id %> diff --git a/app/views/devise/password_expired/show.html.erb b/app/views/devise/password_expired/show.html.erb index cf008fe35..ac3fd10ae 100644 --- a/app/views/devise/password_expired/show.html.erb +++ b/app/views/devise/password_expired/show.html.erb @@ -3,10 +3,7 @@ <%= form_for(resource, :as => resource_name, :url => [resource_name, :password_expired], :html => { :method => :put }) do |f| %> <%= f.password_field :current_password %>

- - <%= f.label t("devise.password_expired.new_password") %> - <%= f.password_field :password, label: false %>

- + <%= f.password_field :password, label: t("devise.password_expired.new_password") %>

<%= f.password_field :password_confirmation %>

<%= f.submit t("devise.password_expired.change_password") %>

diff --git a/app/views/direct_messages/new.html.erb b/app/views/direct_messages/new.html.erb index fef4d84dc..202dff6c8 100644 --- a/app/views/direct_messages/new.html.erb +++ b/app/views/direct_messages/new.html.erb @@ -23,11 +23,8 @@ <%= form_for [@receiver, @direct_message] do |f| %> <%= render "shared/errors", resource: @direct_message %> - <%= f.label :title, t("users.direct_messages.new.title_label") %> - <%= f.text_field :title, label: false %> - - <%= f.label :body, t("users.direct_messages.new.body_label") %> - <%= f.text_area :body, label: false, rows: "3" %> + <%= f.text_field :title, label: t("users.direct_messages.new.title_label") %> + <%= f.text_area :body, label: t("users.direct_messages.new.body_label"), rows: "3" %>
<%= f.submit t("users.direct_messages.new.submit_button"), class: "button expanded" %> diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index e48f149ec..95e15ae21 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -5,8 +5,10 @@
- <%= f.label :title, t("proposals.form.proposal_title") %> - <%= f.text_field :title, maxlength: Legislation::Proposal.title_max_length, placeholder: t("proposals.form.proposal_title"), label: false %> + <%= f.text_field :title, + maxlength: Legislation::Proposal.title_max_length, + placeholder: t("proposals.form.proposal_title"), + label: t("proposals.form.proposal_title") %>
<%= f.invisible_captcha :subtitle %> @@ -20,8 +22,10 @@
- <%= f.label :description, t("proposals.form.proposal_text") %> - <%= f.cktext_area :description, maxlength: Legislation::Proposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %> + <%= f.cktext_area :description, + maxlength: Legislation::Proposal.description_max_length, + ckeditor: { language: I18n.locale }, + label: t("proposals.form.proposal_text") %>
@@ -42,8 +46,8 @@
- <%= f.label :geozone_id, t("proposals.form.geozone") %> - <%= f.select :geozone_id, geozone_select_options, { include_blank: t("geozones.none"), label: false } %> + <%= f.select :geozone_id, geozone_select_options, + include_blank: t("geozones.none"), label: t("proposals.form.geozone") %>
diff --git a/app/views/management/users/new.html.erb b/app/views/management/users/new.html.erb index ce5b5a01a..8c8b4c5a4 100644 --- a/app/views/management/users/new.html.erb +++ b/app/views/management/users/new.html.erb @@ -13,11 +13,10 @@ label: t("management.users.email_optional_label"), placeholder: t("management.email_label") %>
- <%= f.label t("management.date_of_birth") %> <%= f.date_select :date_of_birth, prompt: true, start_year: 1900, end_year: 16.years.ago.year, - label: false %> + label: t("management.date_of_birth") %>
<%= f.submit t("management.users.create_user_submit"), class: "button success" %> <% end %> diff --git a/app/views/proposal_notifications/new.html.erb b/app/views/proposal_notifications/new.html.erb index cee18f1d8..408be1404 100644 --- a/app/views/proposal_notifications/new.html.erb +++ b/app/views/proposal_notifications/new.html.erb @@ -20,12 +20,8 @@ <%= form_for @notification do |f| %> <%= render "shared/errors", resource: @notification %> - <%= f.label :title, t("proposal_notifications.new.title_label") %> - <%= f.text_field :title, label: false %> - - <%= f.label :body, t("proposal_notifications.new.body_label") %> - <%= f.text_area :body, label: false, rows: "3" %> - + <%= f.text_field :title, label: t("proposal_notifications.new.title_label") %> + <%= f.text_area :body, label: t("proposal_notifications.new.body_label"), rows: "3" %> <%= f.hidden_field :proposal_id, value: @proposal.id %>
diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index 415536e85..ef5eb2dd7 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -58,8 +58,8 @@ <% end %>
- <%= f.label :geozone_id, t("proposals.form.geozone") %> - <%= f.select :geozone_id, geozone_select_options, { include_blank: t("geozones.none"), label: false } %> + <%= f.select :geozone_id, geozone_select_options, + include_blank: t("geozones.none"), label: t("proposals.form.geozone") %>
<% if feature?(:map) %> diff --git a/app/views/proposals/retire_form.html.erb b/app/views/proposals/retire_form.html.erb index 9de4bd3ba..6c1e5e182 100644 --- a/app/views/proposals/retire_form.html.erb +++ b/app/views/proposals/retire_form.html.erb @@ -16,8 +16,9 @@ <%= render "shared/errors", resource: @proposal %>
- <%= f.label :retired_reason, t("proposals.retire_form.retired_reason_label") %> - <%= f.select :retired_reason, retire_proposals_options, { include_blank: t("proposals.retire_form.retired_reason_blank"), label: false } %> + <%= f.select :retired_reason, retire_proposals_options, + include_blank: t("proposals.retire_form.retired_reason_blank"), + label: t("proposals.retire_form.retired_reason_label") %>
diff --git a/app/views/shared/_map.html.erb b/app/views/shared/_map.html.erb index 499b1e47e..e2112e7a5 100644 --- a/app/views/shared/_map.html.erb +++ b/app/views/shared/_map.html.erb @@ -31,9 +31,8 @@ <%= form_for(@resource, url: new_url_path, method: :get) do |f| %>
- <%= f.label :geozone_id, t("map.select_district") %> <%= f.select :geozone_id, geozone_select_options, - { include_blank: t("geozones.none"), label: false } %> + include_blank: t("geozones.none"), label: t("map.select_district") %>
diff --git a/app/views/topics/_form.html.erb b/app/views/topics/_form.html.erb index 3ec5982d1..2119ee5b6 100644 --- a/app/views/topics/_form.html.erb +++ b/app/views/topics/_form.html.erb @@ -4,11 +4,8 @@
- <%= f.label :title, t("community.topic.form.topic_title") %> - <%= f.text_field :title, label: false %> - - <%= f.label :description, t("community.topic.form.topic_text") %> - <%= f.text_area :description, label: false, rows: "5" %> + <%= f.text_field :title, label: t("community.topic.form.topic_title") %> + <%= f.text_area :description, label: t("community.topic.form.topic_text"), rows: "5" %> <%= f.submit(class: "button", value: t("community.topic.form.#{action_name}.submit_button")) %>
diff --git a/app/views/tracking/milestones/_form.html.erb b/app/views/tracking/milestones/_form.html.erb index a6fd6687a..e56e69682 100644 --- a/app/views/tracking/milestones/_form.html.erb +++ b/app/views/tracking/milestones/_form.html.erb @@ -27,10 +27,9 @@
- <%= f.label :publication_date, t("tracking.milestones.new.date") %> <%= f.text_field :publication_date, value: @milestone.publication_date.present? ? l(@milestone.publication_date.to_date) : nil, - label: false, + label: t("tracking.milestones.new.date"), class: "js-calendar-full" %> <%= render "images/admin_image", imageable: @milestone, f: f %> diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb index c4abc987d..105a8ca5a 100644 --- a/app/views/users/registrations/edit.html.erb +++ b/app/views/users/registrations/edit.html.erb @@ -6,8 +6,10 @@ <%= render "shared/errors", resource: resource %>
- <%= f.label :email, t("devise_views.users.registrations.edit.email_label") %> - <%= f.email_field :email, label: false, autofocus: true, placeholder: t("devise_views.users.registrations.edit.email_label") %> + <%= f.email_field :email, + label: t("devise_views.users.registrations.edit.email_label"), + autofocus: true, + placeholder: t("devise_views.users.registrations.edit.email_label") %>
@@ -25,8 +27,10 @@
- <%= f.label :password_confirmation, t("devise_views.users.registrations.edit.password_confirmation_label") %> - <%= f.password_field :password_confirmation, label: false, autocomplete: "off", placeholder: t("devise_views.users.registrations.edit.password_confirmation_label") %> + <%= f.password_field :password_confirmation, + label: t("devise_views.users.registrations.edit.password_confirmation_label"), + autocomplete: "off", + placeholder: t("devise_views.users.registrations.edit.password_confirmation_label") %>
diff --git a/app/views/valuation/budget_investments/_dossier_form.html.erb b/app/views/valuation/budget_investments/_dossier_form.html.erb index 469fce699..60ec0e2d5 100644 --- a/app/views/valuation/budget_investments/_dossier_form.html.erb +++ b/app/views/valuation/budget_investments/_dossier_form.html.erb @@ -7,22 +7,22 @@ <%= t("valuation.budget_investments.edit.feasibility") %>
- <%= f.radio_button :feasibility, "undecided", label: false %> - <%= f.label :feasibility_undecided, t("valuation.budget_investments.edit.undefined_feasible") %> + <%= f.radio_button :feasibility, "undecided", + label: t("valuation.budget_investments.edit.undefined_feasible") %>
- <%= f.radio_button :feasibility, "feasible", label: false %> - <%= f.label :feasibility_feasible, t("valuation.budget_investments.edit.feasible") %> + <%= f.radio_button :feasibility, "feasible", + label: t("valuation.budget_investments.edit.feasible") %>
- <%= f.radio_button :feasibility, "unfeasible", label: false %> - <%= f.label :feasibility_unfeasible, t("valuation.budget_investments.edit.unfeasible") %> + <%= f.radio_button :feasibility, "unfeasible", + label: t("valuation.budget_investments.edit.unfeasible") %>
@@ -33,8 +33,9 @@
- <%= f.label :unfeasibility_explanation, t("valuation.budget_investments.edit.feasible_explanation_html") %> - <%= f.text_area :unfeasibility_explanation, label: false, rows: 3 %> + <%= f.text_area :unfeasibility_explanation, + label: t("valuation.budget_investments.edit.feasible_explanation_html"), + rows: 3 %>
@@ -44,27 +45,29 @@
- <%= f.label :price, "#{t("valuation.budget_investments.edit.price_html", currency: budget.currency_symbol)}" %> - <%= f.number_field :price, label: false, max: 1000000000000000 %> + <%= f.number_field :price, + label: t("valuation.budget_investments.edit.price_html", currency: budget.currency_symbol), + max: 1000000000000000 %>
- <%= f.label :price_first_year, "#{t("valuation.budget_investments.edit.price_first_year_html", currency: budget.currency_symbol)}" %> - <%= f.number_field :price_first_year, label: false, max: 1000000000000000 %> + <%= f.number_field :price_first_year, + label: t("valuation.budget_investments.edit.price_first_year_html", currency: budget.currency_symbol), + max: 1000000000000000 %>
- <%= f.label :price_explanation, t("valuation.budget_investments.edit.price_explanation_html") %> - <%= f.text_area :price_explanation, label: false, rows: 3 %> + <%= f.text_area :price_explanation, + label: t("valuation.budget_investments.edit.price_explanation_html"), + rows: 3 %>
- <%= f.label :duration, t("valuation.budget_investments.edit.duration_html") %> - <%= f.text_field :duration, label: false %> + <%= f.text_field :duration, label: t("valuation.budget_investments.edit.duration_html") %>
diff --git a/app/views/verification/residence/new.html.erb b/app/views/verification/residence/new.html.erb index b95523a75..6366ab6d5 100644 --- a/app/views/verification/residence/new.html.erb +++ b/app/views/verification/residence/new.html.erb @@ -39,8 +39,8 @@
- <%= f.label t("verification.residence.new.document_type_label") %> - <%= f.select :document_type, document_types, prompt: "", label: false %> + <%= f.select :document_type, document_types, prompt: "", + label: t("verification.residence.new.document_type_label") %>
@@ -64,11 +64,10 @@
- <%= f.label t("verification.residence.new.date_of_birth") %> <%= f.date_select :date_of_birth, prompt: true, start_year: 1900, end_year: minimum_required_age.years.ago.year, - label: false %> + label: t("verification.residence.new.date_of_birth") %>
diff --git a/app/views/verification/sms/edit.html.erb b/app/views/verification/sms/edit.html.erb index 51189f2bc..af9c70e1f 100644 --- a/app/views/verification/sms/edit.html.erb +++ b/app/views/verification/sms/edit.html.erb @@ -33,8 +33,7 @@ <% end %>
- <%= f.label t("verification.sms.edit.confirmation_code") %> - <%= f.text_field :confirmation_code, label: false %> + <%= f.text_field :confirmation_code, label: t("verification.sms.edit.confirmation_code") %>
<%= f.submit t("verification.sms.edit.submit_button"), class: "button success" %> From ae6fab9f5eea7a3f843e870e43a3886309aacd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Oct 2019 00:49:28 +0200 Subject: [PATCH 2/8] Inherit from builder instead of monkey patching it We were monkey-patching FoundationRailsHelper::Formbuilder, which made form customization difficult. We can inherit from it, which is the standard way of extending what an existing class does, and make our form the default one. --- app/controllers/application_controller.rb | 1 + app/controllers/management/base_controller.rb | 1 + .../management/sessions_controller.rb | 1 + app/helpers/translatable_form_helper.rb | 4 ++-- config/initializers/foundation_rails_helper.rb | 17 ----------------- lib/consul_form_builder.rb | 15 +++++++++++++++ 6 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 config/initializers/foundation_rails_helper.rb create mode 100644 lib/consul_form_builder.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 56d9dc046..ffe4f4f4a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base include HasOrders include AccessDeniedHandler + default_form_builder ConsulFormBuilder protect_from_forgery with: :exception before_action :authenticate_http_basic, if: :http_basic_auth_site? diff --git a/app/controllers/management/base_controller.rb b/app/controllers/management/base_controller.rb index 9f45fab39..78b0f7fc3 100644 --- a/app/controllers/management/base_controller.rb +++ b/app/controllers/management/base_controller.rb @@ -1,6 +1,7 @@ class Management::BaseController < ActionController::Base include GlobalizeFallbacks layout "management" + default_form_builder ConsulFormBuilder before_action :verify_manager before_action :set_locale diff --git a/app/controllers/management/sessions_controller.rb b/app/controllers/management/sessions_controller.rb index 5617c22fb..066fc6a9f 100644 --- a/app/controllers/management/sessions_controller.rb +++ b/app/controllers/management/sessions_controller.rb @@ -3,6 +3,7 @@ require "manager_authenticator" class Management::SessionsController < ActionController::Base include GlobalizeFallbacks include AccessDeniedHandler + default_form_builder ConsulFormBuilder def create destroy_session diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index ecd0a16a1..0b98b36b5 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -18,7 +18,7 @@ module TranslatableFormHelper "highlight" if translations_interface_enabled? end - class TranslatableFormBuilder < FoundationRailsHelper::FormBuilder + class TranslatableFormBuilder < ConsulFormBuilder attr_accessor :translations def translatable_fields(&block) @@ -94,7 +94,7 @@ module TranslatableFormHelper end end - class TranslationsFieldsBuilder < FoundationRailsHelper::FormBuilder + class TranslationsFieldsBuilder < ConsulFormBuilder %i[text_field text_area cktext_area].each do |field| define_method field do |attribute, options = {}| custom_label(attribute, options[:label], options[:label_options]) + diff --git a/config/initializers/foundation_rails_helper.rb b/config/initializers/foundation_rails_helper.rb deleted file mode 100644 index 3e121f0d9..000000000 --- a/config/initializers/foundation_rails_helper.rb +++ /dev/null @@ -1,17 +0,0 @@ -module FoundationRailsHelper - class FormBuilder < ActionView::Helpers::FormBuilder - def cktext_area(attribute, options) - field(attribute, options) do |opts| - super(attribute, opts) - end - end - - def enum_select(attribute, options = {}, html_options = {}) - choices = object.class.send(attribute.to_s.pluralize).keys.map do |name| - [object.class.human_attribute_name("#{attribute}.#{name}"), name] - end - - select attribute, choices, options, html_options - end - end -end diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb new file mode 100644 index 000000000..fa78fa5ea --- /dev/null +++ b/lib/consul_form_builder.rb @@ -0,0 +1,15 @@ +class ConsulFormBuilder < FoundationRailsHelper::FormBuilder + def cktext_area(attribute, options) + field(attribute, options) do |opts| + super(attribute, opts) + end + end + + def enum_select(attribute, options = {}, html_options = {}) + choices = object.class.send(attribute.to_s.pluralize).keys.map do |name| + [object.class.human_attribute_name("#{attribute}.#{name}"), name] + end + + select attribute, choices, options, html_options + end +end From 4a19bb6b777d73de1bf8bd1c93384dd8011577e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Oct 2019 02:25:14 +0200 Subject: [PATCH 3/8] Simplify generating fields with hints We were already using this code in translatable forms. Using it on every form means we can reduce the code we need to generate a field with a hint. --- app/helpers/translatable_form_helper.rb | 22 ---------------- app/views/admin/budget_phases/_form.html.erb | 18 +++---------- .../admin/dashboard/actions/_form.html.erb | 15 +++++------ app/views/admin/geozones/_form.html.erb | 12 +++------ .../legislation/proposals/_form.html.erb | 5 ++-- app/views/admin/signature_sheets/new.html.erb | 6 ++--- .../site_customization/pages/_form.html.erb | 5 ++-- lib/consul_form_builder.rb | 26 ++++++++++++++----- 8 files changed, 39 insertions(+), 70 deletions(-) diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index 0b98b36b5..92eff3d33 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -95,30 +95,8 @@ module TranslatableFormHelper end class TranslationsFieldsBuilder < ConsulFormBuilder - %i[text_field text_area cktext_area].each do |field| - define_method field do |attribute, options = {}| - custom_label(attribute, options[:label], options[:label_options]) + - help_text(options[:hint]) + - super(attribute, options.merge(label: false, hint: false)) - end - end - def locale @object.locale end - - def label(attribute, text = nil, options = {}) - label_options = options.dup - hint = label_options.delete(:hint) - - super(attribute, text, label_options) + help_text(hint) - end - - private - def help_text(text) - if text - content_tag :span, text, class: "help-text" - end - end end end diff --git a/app/views/admin/budget_phases/_form.html.erb b/app/views/admin/budget_phases/_form.html.erb index 8a3e94c4c..5251b3254 100644 --- a/app/views/admin/budget_phases/_form.html.erb +++ b/app/views/admin/budget_phases/_form.html.erb @@ -24,30 +24,20 @@
<%= f.translatable_fields do |translations_form| %>
- <%= f.label :description, t("admin.budget_phases.edit.description") %> - - - <%= t("admin.budget_phases.edit.description_help_text") %> - -
<%= translations_form.cktext_area :description, maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH, - label: false %> + label: t("admin.budget_phases.edit.description"), + hint: t("admin.budget_phases.edit.description_help_text") %>
- <%= f.label :summary, t("admin.budget_phases.edit.summary") %> - - - <%= t("admin.budget_phases.edit.summary_help_text") %> - -
<%= translations_form.cktext_area :summary, maxlength: Budget::Phase::SUMMARY_MAX_LENGTH, - label: false %> + label: t("admin.budget_phases.edit.summary"), + hint: t("admin.budget_phases.edit.summary_help_text") %>
<% end %> diff --git a/app/views/admin/dashboard/actions/_form.html.erb b/app/views/admin/dashboard/actions/_form.html.erb index 5e7499451..f018bb1f2 100644 --- a/app/views/admin/dashboard/actions/_form.html.erb +++ b/app/views/admin/dashboard/actions/_form.html.erb @@ -47,21 +47,18 @@
- <%= f.label :day_offset %> -

<%= t("admin.dashboard.actions.form.help_text") %>

- <%= f.number_field :day_offset, label: false, step: 1, min: 0 %> + <%= f.number_field :day_offset, step: 1, min: 0, + hint: t("admin.dashboard.actions.form.help_text") %>
- <%= f.label :required_supports %> -

<%= t("admin.dashboard.actions.form.help_text") %>

- <%= f.number_field :required_supports, label: false, step: 1, min: 0 %> + <%= f.number_field :required_supports, step: 1, min: 0, + hint: t("admin.dashboard.actions.form.help_text") %>
- <%= f.label :order %> -

<%= t("admin.dashboard.actions.form.help_text") %>

- <%= f.number_field :order, label: false, step: 1, min: 0 %> + <%= f.number_field :order, step: 1, min: 0, + hint: t("admin.dashboard.actions.form.help_text") %>
diff --git a/app/views/admin/geozones/_form.html.erb b/app/views/admin/geozones/_form.html.erb index 0a1bde3d9..516ce7ef1 100644 --- a/app/views/admin/geozones/_form.html.erb +++ b/app/views/admin/geozones/_form.html.erb @@ -8,22 +8,16 @@
- <%= f.label :census_code %> -

<%= t("admin.geozones.geozone.code_help") %>

- <%= f.text_field :census_code, label: false %> + <%= f.text_field :census_code, hint: t("admin.geozones.geozone.code_help") %>
- <%= f.label :external_code %> -

<%= t("admin.geozones.geozone.code_help") %>

- <%= f.text_field :external_code, label: false %> + <%= f.text_field :external_code, hint: t("admin.geozones.geozone.code_help") %>
- <%= f.label :html_map_coordinates %> -

<%= t("admin.geozones.geozone.coordinates_help") %>

- <%= f.text_field :html_map_coordinates, label: false %> + <%= f.text_field :html_map_coordinates, hint: t("admin.geozones.geozone.coordinates_help") %>
diff --git a/app/views/admin/legislation/proposals/_form.html.erb b/app/views/admin/legislation/proposals/_form.html.erb index 19e0afe3a..536521187 100644 --- a/app/views/admin/legislation/proposals/_form.html.erb +++ b/app/views/admin/legislation/proposals/_form.html.erb @@ -16,10 +16,9 @@ <% end %>
- <%= f.label :custom_list, t("admin.legislation.proposals.form.custom_categories") %> - <%= t("admin.legislation.proposals.form.custom_categories_description") %> <%= f.text_field :custom_list, value: @process.tag_list_on(:customs).to_s, - label: false, + label: t("admin.legislation.proposals.form.custom_categories"), + hint: t("admin.legislation.proposals.form.custom_categories_description"), placeholder: t("admin.legislation.proposals.form.custom_categories_placeholder"), class: "js-tag-list", aria: { describedby: "tag-list-help-text" } %> diff --git a/app/views/admin/signature_sheets/new.html.erb b/app/views/admin/signature_sheets/new.html.erb index bf88f1ca7..f851ebd0f 100644 --- a/app/views/admin/signature_sheets/new.html.erb +++ b/app/views/admin/signature_sheets/new.html.erb @@ -14,10 +14,8 @@ <%= f.text_field :signable_id %>
- <%= f.label :required_fields_to_verify %> -

<%= required_fields_to_verify_text_help %>

-

<%= example_text_help %>

- <%= f.text_area :required_fields_to_verify, rows: "6", label: false, aria: { describedby: "required-fields-to-verify-help-text" } %> + <%= f.text_area :required_fields_to_verify, rows: "6", + hint: sanitize("#{required_fields_to_verify_text_help}
#{example_text_help}") %> <%= f.submit(class: "button", value: t("admin.signature_sheets.new.submit")) %> <% end %> diff --git a/app/views/admin/site_customization/pages/_form.html.erb b/app/views/admin/site_customization/pages/_form.html.erb index dbe602451..7396b4cec 100644 --- a/app/views/admin/site_customization/pages/_form.html.erb +++ b/app/views/admin/site_customization/pages/_form.html.erb @@ -32,9 +32,8 @@
- <%= f.label :slug %> -

<%= t("admin.site_customization.pages.new.slug_help_html") %> - <%= f.text_field :slug, label: false, size: 80, maxlength: 80 %> + <%= f.text_field :slug, size: 80, maxlength: 80, + hint: t("admin.site_customization.pages.new.slug_help_html") %>

diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb index fa78fa5ea..c8c3692a9 100644 --- a/lib/consul_form_builder.rb +++ b/lib/consul_form_builder.rb @@ -1,10 +1,4 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder - def cktext_area(attribute, options) - field(attribute, options) do |opts| - super(attribute, opts) - end - end - def enum_select(attribute, options = {}, html_options = {}) choices = object.class.send(attribute.to_s.pluralize).keys.map do |name| [object.class.human_attribute_name("#{attribute}.#{name}"), name] @@ -12,4 +6,24 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder select attribute, choices, options, html_options end + + %i[text_field text_area cktext_area number_field password_field email_field].each do |field| + define_method field do |attribute, options = {}| + label_with_hint(attribute, options) + + super(attribute, options.merge(label: false, hint: false)) + end + end + + private + + def label_with_hint(attribute, options) + custom_label(attribute, options[:label], options[:label_options]) + + help_text(options[:hint]) + end + + def help_text(text) + if text + content_tag :span, text, class: "help-text" + end + end end From 4f5de5be3bd5f1d2f11cb0e3168f1234f4d149ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Oct 2019 02:51:54 +0200 Subject: [PATCH 4/8] Add aria-describedby attribute automatically We were manually adding the attribute in many places, but not everywhere. I'm assuming adding it where we didn't have it is doing no harm. --- app/helpers/proposals_helper.rb | 4 ---- .../admin/budget_headings/_form.html.erb | 8 ++----- app/views/debates/_form.html.erb | 7 ++----- .../legislation/proposals/_form.html.erb | 17 +++++++-------- .../organizations/registrations/new.html.erb | 9 ++++---- app/views/proposals/_form.html.erb | 21 +++++++------------ app/views/users/registrations/edit.html.erb | 20 +++++++++--------- app/views/users/registrations/new.html.erb | 5 +---- app/views/verification/residence/new.html.erb | 8 +++---- lib/consul_form_builder.rb | 19 ++++++++++++----- 10 files changed, 51 insertions(+), 67 deletions(-) diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index ff8659dd2..1310dfc1c 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -64,10 +64,6 @@ module ProposalsHelper proposals_current_view == "default" ? "minimal" : "default" end - def summary_help_text_id(translations_form) - "summary-help-text-#{translations_form.locale}" - end - def link_to_toggle_proposal_selection(proposal) if proposal.selected? button_text = t("admin.proposals.index.selected") diff --git a/app/views/admin/budget_headings/_form.html.erb b/app/views/admin/budget_headings/_form.html.erb index fd3c9bc58..827afed60 100644 --- a/app/views/admin/budget_headings/_form.html.erb +++ b/app/views/admin/budget_headings/_form.html.erb @@ -22,16 +22,12 @@ maxlength: 8, placeholder: t("admin.budget_headings.form.amount") %> - <%= f.label :population, t("admin.budget_headings.form.population") %> -

- <%= t("admin.budget_headings.form.population_info") %> -

<%= f.text_field :population, - label: false, + label: t("admin.budget_headings.form.population"), maxlength: 8, placeholder: t("admin.budget_headings.form.population"), data: { toggle_focus: "population-info" }, - aria: { describedby: "budgets-population-help-text" } %> + hint: t("admin.budget_headings.form.population_info") %> <%= f.text_field :latitude, label: t("admin.budget_headings.form.latitude"), diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 87c559a62..7075e1cf0 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -26,13 +26,10 @@ <%= f.invisible_captcha :subtitle %>
- <%= f.label :tag_list, t("debates.form.tags_label") %> -

<%= t("debates.form.tags_instructions") %>

- <%= f.text_field :tag_list, value: @debate.tag_list.to_s, - label: false, + label: t("debates.form.tags_label"), + hint: t("debates.form.tags_instructions"), placeholder: t("debates.form.tags_placeholder"), - aria: { describedby: "tag-list-help-text" }, data: { js_url: suggest_tags_path }, class: "tag-autocomplete" %>
diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 95e15ae21..8fd543039 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -14,11 +14,10 @@ <%= f.invisible_captcha :subtitle %>
- <%= f.label :summary, t("proposals.form.proposal_summary") %> -

<%= t("proposals.form.proposal_summary_note") %>

- <%= f.text_area :summary, rows: 4, maxlength: 200, label: false, - placeholder: t("proposals.form.proposal_summary"), - aria: { describedby: "summary-help-text" } %> + <%= f.text_area :summary, rows: 4, maxlength: 200, + label: t("proposals.form.proposal_summary"), + placeholder: t("proposals.form.proposal_summary"), + hint: t("proposals.form.proposal_summary_note") %>
@@ -29,10 +28,10 @@
- <%= f.label :video_url, t("proposals.form.proposal_video_url") %> -

<%= t("proposals.form.proposal_video_url_note") %>

- <%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false, - aria: { describedby: "video-url-help-text" } %> + <%= f.text_field :video_url, + placeholder: t("proposals.form.proposal_video_url"), + label: t("proposals.form.proposal_video_url"), + hint: t("proposals.form.proposal_video_url_note") %>
<% if feature?(:allow_images) %> diff --git a/app/views/organizations/registrations/new.html.erb b/app/views/organizations/registrations/new.html.erb index a8667127f..db354259e 100644 --- a/app/views/organizations/registrations/new.html.erb +++ b/app/views/organizations/registrations/new.html.erb @@ -8,11 +8,10 @@ <%= f.fields_for :organization do |fo| %> <%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("devise_views.organizations.registrations.new.organization_name_label") %> - <%= fo.label :responsible_name %> -

<%= t("devise_views.organizations.registrations.new.responsible_name_note") %>

- <%= fo.text_field :responsible_name, placeholder: t("devise_views.organizations.registrations.new.responsible_name_label"), - maxlength: Organization.responsible_name_max_length, label: false, - aria: { describedby: "responsible-name-help-text" } %> + <%= fo.text_field :responsible_name, + placeholder: t("devise_views.organizations.registrations.new.responsible_name_label"), + maxlength: Organization.responsible_name_max_length, + hint: t("devise_views.organizations.registrations.new.responsible_name_note") %> <% end %> <%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %> diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index ef5eb2dd7..d87385e20 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -17,15 +17,10 @@
- <%= translations_form.label :summary %> -

- <%= t("proposals.form.proposal_summary_note") %> -

<%= translations_form.text_area :summary, rows: 4, maxlength: 200, - label: false, placeholder: t("proposals.form.proposal_summary"), - aria: { describedby: summary_help_text_id(translations_form) } %> + hint: t("proposals.form.proposal_summary_note") %>
@@ -38,11 +33,9 @@ <%= f.invisible_captcha :subtitle %>
- <%= f.label :video_url, t("proposals.form.proposal_video_url") %> -

<%= t("proposals.form.proposal_video_url_note") %>

<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), - label: false, - aria: { describedby: "video-url-help-text" } %> + label: t("proposals.form.proposal_video_url"), + hint: t("proposals.form.proposal_video_url_note") %>
<% if feature?(:allow_images) %> @@ -99,10 +92,10 @@ <% if current_user.unverified? %>
- <%= f.label :responsible_name, t("proposals.form.proposal_responsible_name") %> -

<%= t("proposals.form.proposal_responsible_name_note") %>

- <%= f.text_field :responsible_name, placeholder: t("proposals.form.proposal_responsible_name"), label: false, - aria: { describedby: "responsible-name-help-text" } %> + <%= f.text_field :responsible_name, + placeholder: t("proposals.form.proposal_responsible_name"), + label: t("proposals.form.proposal_responsible_name"), + hint: t("proposals.form.proposal_responsible_name_note") %>
<% end %> diff --git a/app/views/users/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb index 105a8ca5a..eee748ec5 100644 --- a/app/views/users/registrations/edit.html.erb +++ b/app/views/users/registrations/edit.html.erb @@ -19,11 +19,11 @@
- <%= f.label :password, t("devise_views.users.registrations.edit.password_label") %> -

<%= t("devise_views.users.registrations.edit.leave_blank") %>

- <%= f.password_field :password, autocomplete: "off", label: false, - placeholder: t("devise_views.users.registrations.edit.password_label"), - aria: { describedby: "password-help-text" } %> + <%= f.password_field :password, + autocomplete: "off", + label: t("devise_views.users.registrations.edit.password_label"), + placeholder: t("devise_views.users.registrations.edit.password_label"), + hint: t("devise_views.users.registrations.edit.leave_blank") %>
@@ -34,11 +34,11 @@
- <%= f.label :current_password, t("devise_views.users.registrations.edit.current_password_label") %> -

<%= t("devise_views.users.registrations.edit.need_current") %>

- <%= f.password_field :current_password, label: false, autocomplete: "off", - placeholder: t("devise_views.users.registrations.edit.current_password_label"), - aria: { describedby: "current-password-help-text" } %> + <%= f.password_field :current_password, + label: t("devise_views.users.registrations.edit.current_password_label"), + autocomplete: "off", + placeholder: t("devise_views.users.registrations.edit.current_password_label"), + hint: t("devise_views.users.registrations.edit.need_current") %>
diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 9d3336178..7309606a4 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -17,12 +17,9 @@ <%= f.hidden_field :use_redeemable_code %> <%= f.hidden_field :locale, value: I18n.locale %> - <%= f.label :username %> -

<%= t("devise_views.users.registrations.new.username_note") %>

<%= f.text_field :username, autofocus: true, maxlength: User.username_max_length, placeholder: t("devise_views.users.registrations.new.username_label"), - label: false, - aria: { describedby: "username-help-text" } %> + hint: t("devise_views.users.registrations.new.username_note") %> <%= f.invisible_captcha :address %> diff --git a/app/views/verification/residence/new.html.erb b/app/views/verification/residence/new.html.erb index 6366ab6d5..c18d42ccc 100644 --- a/app/views/verification/residence/new.html.erb +++ b/app/views/verification/residence/new.html.erb @@ -71,11 +71,9 @@
- <%= f.label t("verification.residence.new.postal_code") %> -

<%= t("verification.residence.new.postal_code_note") %>

-
- <%= f.text_field :postal_code, label: false, aria: { describedby: "postal-code-help-text" } %> -
+ <%= f.text_field :postal_code, + label: t("verification.residence.new.postal_code"), + hint: t("verification.residence.new.postal_code_note") %>
diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb index c8c3692a9..fd7a24c98 100644 --- a/lib/consul_form_builder.rb +++ b/lib/consul_form_builder.rb @@ -10,7 +10,10 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder %i[text_field text_area cktext_area number_field password_field email_field].each do |field| define_method field do |attribute, options = {}| label_with_hint(attribute, options) + - super(attribute, options.merge(label: false, hint: false)) + super(attribute, options.merge( + label: false, hint: false, + aria: { describedby: help_text_id(attribute, options) } + )) end end @@ -18,12 +21,18 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder def label_with_hint(attribute, options) custom_label(attribute, options[:label], options[:label_options]) + - help_text(options[:hint]) + help_text(attribute, options) end - def help_text(text) - if text - content_tag :span, text, class: "help-text" + def help_text(attribute, options) + if options[:hint] + content_tag :span, options[:hint], class: "help-text", id: help_text_id(attribute, options) + end + end + + def help_text_id(attribute, options) + if options[:hint] + "#{custom_label(attribute, nil, nil).match(/for=\"(.+)\"/)[1]}-help-text" end end end From 5fe56a62f16b475eed24dcb83e7ee431766a57cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Oct 2019 04:09:43 +0200 Subject: [PATCH 5/8] Remove useless label false parameter in select_tag `select_tag` creates just a select with no label, so there's no need to specify `label: false`. --- .../budget_investments/_search_form.html.erb | 15 +++++---------- app/views/admin/poll/shifts/_form.html.erb | 6 ++---- .../_form_heading_content_block.html.erb | 4 ++-- app/views/officing/ballot_sheets/new.html.erb | 2 +- app/views/officing/results/new.html.erb | 3 +-- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/views/admin/budget_investments/_search_form.html.erb b/app/views/admin/budget_investments/_search_form.html.erb index 80b722bed..b6c24b1a1 100644 --- a/app/views/admin/budget_investments/_search_form.html.erb +++ b/app/views/admin/budget_investments/_search_form.html.erb @@ -35,33 +35,28 @@
<%= select_tag :administrator_id, options_for_select(admin_select_options, params[:administrator_id]), - { prompt: t("admin.budget_investments.index.administrator_filter_all"), - label: false } %> + { prompt: t("admin.budget_investments.index.administrator_filter_all") } %>
<%= select_tag :valuator_or_group_id, options_for_select(valuator_or_group_select_options, params[:valuator_or_group_id]), - { prompt: t("admin.budget_investments.index.valuator_filter_all"), - label: false } %> + { prompt: t("admin.budget_investments.index.valuator_filter_all") } %>
<%= select_tag :heading_id, options_for_select(budget_heading_select_options(@budget), params[:heading_id]), - { prompt: t("admin.budget_investments.index.heading_filter_all"), - label: false } %> + { prompt: t("admin.budget_investments.index.heading_filter_all") } %>
<%= select_tag :tag_name, options_for_select(investment_tags_select_options(@budget), params[:tag_name]), - { prompt: t("admin.budget_investments.index.tags_filter_all"), - label: false } %> + { prompt: t("admin.budget_investments.index.tags_filter_all") } %>
<%= select_tag :milestone_tag_name, options_for_select(investment_milestone_tags_select_options(@budget), params[:milestone_tag_name]), - { prompt: t("admin.budget_investments.index.milestone_tags_filter_all"), - label: false } %> + { prompt: t("admin.budget_investments.index.milestone_tags_filter_all") } %>
diff --git a/app/views/admin/poll/shifts/_form.html.erb b/app/views/admin/poll/shifts/_form.html.erb index 5b0f86e7c..c09f63d85 100644 --- a/app/views/admin/poll/shifts/_form.html.erb +++ b/app/views/admin/poll/shifts/_form.html.erb @@ -23,13 +23,11 @@ <%= select "shift[date]", "vote_collection_date", options_for_select(shift_vote_collection_dates(@booth, @voting_polls)), - { prompt: @voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days"), - label: false }, + { prompt: @voting_polls.present? ? t("admin.poll_shifts.new.select_date") : t("admin.poll_shifts.new.no_voting_days") }, class: "js-shift-vote-collection-dates" %> <%= select "shift[date]", "recount_scrutiny_date", options_for_select(shift_recount_scrutiny_dates(@booth, @recount_polls)), - { prompt: t("admin.poll_shifts.new.select_date"), - label: false }, + { prompt: t("admin.poll_shifts.new.select_date") }, class: "js-shift-recount-scrutiny-dates", hidden: "hidden" %>
diff --git a/app/views/admin/site_customization/content_blocks/_form_heading_content_block.html.erb b/app/views/admin/site_customization/content_blocks/_form_heading_content_block.html.erb index 3f9e8e4b8..f05f0c1e9 100644 --- a/app/views/admin/site_customization/content_blocks/_form_heading_content_block.html.erb +++ b/app/views/admin/site_customization/content_blocks/_form_heading_content_block.html.erb @@ -13,11 +13,11 @@
<%= label_tag :name %> - <%= select_tag :name, options_for_select(valid_blocks, @selected_content_block), label: false %> + <%= select_tag :name, options_for_select(valid_blocks, @selected_content_block) %>
<%= label_tag :locale %> - <%= select_tag :locale, options_for_select(I18n.available_locales, @content_block.locale.to_sym), label: false %> + <%= select_tag :locale, options_for_select(I18n.available_locales, @content_block.locale.to_sym) %>
<%= label_tag :body %> diff --git a/app/views/officing/ballot_sheets/new.html.erb b/app/views/officing/ballot_sheets/new.html.erb index a83c3a7d0..a715933d0 100644 --- a/app/views/officing/ballot_sheets/new.html.erb +++ b/app/views/officing/ballot_sheets/new.html.erb @@ -5,7 +5,7 @@ <%= select_tag :officer_assignment_id, booths_for_officer_select_options(@officer_assignments), - { prompt: t("officing.poll_budgets.new.select_booth"), label: false } %> + { prompt: t("officing.poll_budgets.new.select_booth") } %> <%= text_area_tag :data, nil, rows: 10 %> diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb index 39cde8186..9b2855133 100644 --- a/app/views/officing/results/new.html.erb +++ b/app/views/officing/results/new.html.erb @@ -7,8 +7,7 @@ <%= select_tag :officer_assignment_id, booths_for_officer_select_options(@officer_assignments), - { prompt: t("officing.results.new.select_booth"), - label: false } %> + { prompt: t("officing.results.new.select_booth") } %>
From 8d9cb4d8e31fa79fe2d30cf08f018e607c77b5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Oct 2019 18:53:26 +0200 Subject: [PATCH 6/8] Simplify generating checkboxes in forms Using the block syntax to generate the label with a tag inside isn't necessary after upgrading foundation_rails_helpers. Before the upgrade, we couldn't do so because the tag was escaped. --- app/views/account/show.html.erb | 72 +++---------------- .../admin/budget_investments/edit.html.erb | 14 ++-- app/views/budgets/investments/_form.html.erb | 13 ++-- app/views/comments/_form.html.erb | 12 ++-- app/views/debates/_form.html.erb | 14 ++-- app/views/devise/sessions/new.html.erb | 5 +- .../legislation/proposals/_form.html.erb | 14 ++-- app/views/map_locations/_form_fields.html.erb | 12 +--- .../organizations/registrations/new.html.erb | 14 ++-- app/views/proposals/_form.html.erb | 14 ++-- app/views/users/registrations/new.html.erb | 17 +++-- .../budget_investments/_dossier_form.html.erb | 14 ++-- app/views/verification/residence/new.html.erb | 17 ++--- lib/consul_form_builder.rb | 18 +++++ 14 files changed, 98 insertions(+), 152 deletions(-) diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index b1fda5247..90ac292d5 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -32,82 +32,40 @@
- <%= f.label :public_activity do %> - <%= f.check_box :public_activity, title: t("account.show.public_activity_label"), label: false %> - - <%= t("account.show.public_activity_label") %> - - <% end %> + <%= f.check_box :public_activity, label: t("account.show.public_activity_label") %>
- <%= f.label :public_interests do %> - <%= f.check_box :public_interests, title: t("account.show.public_interests_label"), label: false %> - - <%= t("account.show.public_interests_label") %> - - <% end %> + <%= f.check_box :public_interests, label: t("account.show.public_interests_label") %>
<% if @account.email.present? %>

<%= t("account.show.notifications") %>

- <%= f.label :email_on_comment do %> - <%= f.check_box :email_on_comment, title: t("account.show.email_on_comment_label"), label: false %> - - <%= t("account.show.email_on_comment_label") %> - - <% end %> + <%= f.check_box :email_on_comment, label: t("account.show.email_on_comment_label") %>
- <%= f.label :email_on_comment_reply do %> - <%= f.check_box :email_on_comment_reply, title: t("account.show.email_on_comment_reply_label"), label: false %> - - <%= t("account.show.email_on_comment_reply_label") %> - - <% end %> + <%= f.check_box :email_on_comment_reply, label: t("account.show.email_on_comment_reply_label") %>
- <%= f.label :email_newsletter_subscribed do %> - <%= f.check_box :newsletter, title: t("account.show.subscription_to_website_newsletter_label"), label: false %> - - <%= t("account.show.subscription_to_website_newsletter_label") %> - - <% end %> + <%= f.check_box :newsletter, label: t("account.show.subscription_to_website_newsletter_label") %>
- <%= f.label :email_digest do %> - <%= f.check_box :email_digest, title: t("account.show.email_digest_label"), label: false %> - - <%= t("account.show.email_digest_label") %> - - <% end %> + <%= f.check_box :email_digest, label: t("account.show.email_digest_label") %>
- <%= f.label :email_on_direct_message do %> - <%= f.check_box :email_on_direct_message, title: t("account.show.email_on_direct_message_label"), label: false %> - - <%= t("account.show.email_on_direct_message_label") %> - - <% end %> + <%= f.check_box :email_on_direct_message, label: t("account.show.email_on_direct_message_label") %>
<% end %> <% if @account.official_level == 1 %>
- <%= f.label :official_position_badge do %> - <%= f.check_box :official_position_badge, - title: t("account.show.official_position_badge_label"), - label: false %> - - <%= t("account.show.official_position_badge_label") %> - - <% end %> + <%= f.check_box :official_position_badge, label: t("account.show.official_position_badge_label") %>
<% end %> @@ -116,23 +74,13 @@ <% if feature?("user.recommendations_on_debates") %>
- <%= f.label :recommended_debates do %> - <%= f.check_box :recommended_debates, title: t("account.show.show_debates_recommendations"), label: false %> - - <%= t("account.show.show_debates_recommendations") %> - - <% end %> + <%= f.check_box :recommended_debates, label: t("account.show.show_debates_recommendations") %>
<% end %> <% if feature?("user.recommendations_on_proposals") %>
- <%= f.label :recommended_proposals do %> - <%= f.check_box :recommended_proposals, title: t("account.show.show_proposals_recommendations"), label: false %> - - <%= t("account.show.show_proposals_recommendations") %> - - <% end %> + <%= f.check_box :recommended_proposals, label: t("account.show.show_proposals_recommendations") %>
<% end %> <% end %> diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index 851b43789..f8a51add9 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -105,18 +105,16 @@ <% if @investment.incompatible? || @investment.winner? %>

<%= t("admin.budget_investments.edit.compatibility") %>

- <%= f.label :incompatible do %> - <%= f.check_box :incompatible, title: t("admin.budget_investments.edit.compatibility"), label: false %> - <%= t("admin.budget_investments.edit.mark_as_incompatible") %> - <% end %> + <%= f.check_box :incompatible, + title: t("admin.budget_investments.edit.compatibility"), + label: t("admin.budget_investments.edit.mark_as_incompatible") %>
<% end %>

<%= t("admin.budget_investments.edit.selection") %>

- <%= f.label :selected do %> - <%= f.check_box :selected, title: t("admin.budget_investments.edit.selection"), label: false %> - <%= t("admin.budget_investments.edit.mark_as_selected") %> - <% end %> + <%= f.check_box :selected, + title: t("admin.budget_investments.edit.selection"), + label: t("admin.budget_investments.edit.mark_as_selected") %>
diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 4fb08a56b..d81a92b06 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -89,14 +89,11 @@ <% unless current_user.manager? %>
- <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %> - - <%= t("form.accept_terms", - policy: link_to(t("form.policy"), "/privacy", target: "blank"), - conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> - - <% end %> + <%= f.check_box :terms_of_service, + title: t("form.accept_terms_title"), + label: t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %>
<% end %> diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 9e828bd08..40613b044 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -18,14 +18,18 @@ <% if can? :comment_as_moderator, commentable %>
- <%= f.check_box :as_moderator, title: t("comments.form.comment_as_moderator"), id: "comment-as-moderator-#{css_id}", label: false %> - <%= label_tag "comment-as-moderator-#{css_id}", t("comments.form.comment_as_moderator"), class: "checkbox" %> + <%= f.check_box :as_moderator, + label: t("comments.form.comment_as_moderator"), + id: "comment-as-moderator-#{css_id}", + label_options: { for: "comment-as-moderator-#{css_id}" } %>
<% end %> <% if can? :comment_as_administrator, commentable %>
- <%= f.check_box :as_administrator, title: t("comments.form.comment_as_admin"), id: "comment-as-administrator-#{css_id}", label: false %> - <%= label_tag "comment-as-administrator-#{css_id}", t("comments.form.comment_as_admin"), class: "checkbox" %> + <%= f.check_box :as_administrator, + label: t("comments.form.comment_as_admin"), + id: "comment-as-administrator-#{css_id}", + label_options: { for: "comment-as-administrator-#{css_id}" } %>
<% end %> diff --git a/app/views/debates/_form.html.erb b/app/views/debates/_form.html.erb index 7075e1cf0..69639fbb4 100644 --- a/app/views/debates/_form.html.erb +++ b/app/views/debates/_form.html.erb @@ -35,14 +35,12 @@
<% if @debate.new_record? %> - <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %> - - <%= t("form.accept_terms", - policy: link_to(t("form.policy"), "/privacy", target: "blank"), - conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> - - <% end %> + <%= f.check_box :terms_of_service, + title: t("form.accept_terms_title"), + label: t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank") + ).html_safe %> <% end %>
diff --git a/app/views/devise/sessions/new.html.erb b/app/views/devise/sessions/new.html.erb index f6e62791d..cba9e6ec0 100644 --- a/app/views/devise/sessions/new.html.erb +++ b/app/views/devise/sessions/new.html.erb @@ -21,10 +21,7 @@ <% if devise_mapping.rememberable? -%>
- <%= f.label :remember_me do %> - <%= f.check_box :remember_me, title: t("devise_views.sessions.new.remember_me"), label: false %> - <%= t("devise_views.sessions.new.remember_me") %> - <% end %> + <%= f.check_box :remember_me, label: t("devise_views.sessions.new.remember_me") %>
<% end -%> diff --git a/app/views/legislation/proposals/_form.html.erb b/app/views/legislation/proposals/_form.html.erb index 8fd543039..b6d702c27 100644 --- a/app/views/legislation/proposals/_form.html.erb +++ b/app/views/legislation/proposals/_form.html.erb @@ -69,14 +69,12 @@
<% if @proposal.new_record? %> - <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %> - - <%= t("form.accept_terms", - policy: link_to(t("form.policy"), "/privacy", target: "blank"), - conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> - - <% end %> + <%= f.check_box :terms_of_service, + title: t("form.accept_terms_title"), + label: t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank") + ).html_safe %> <% end %>
diff --git a/app/views/map_locations/_form_fields.html.erb b/app/views/map_locations/_form_fields.html.erb index f2292a42e..132c39a00 100644 --- a/app/views/map_locations/_form_fields.html.erb +++ b/app/views/map_locations/_form_fields.html.erb @@ -18,14 +18,8 @@ id: map_location_input_id(parent_class, "zoom") %>
- <%= form.label :skip_map do %> - <%= form.check_box :skip_map, - title: t("#{i18n_namespace}.form.map_skip_checkbox"), - label: false, - class: "js-toggle-map" %> - - <%= t("#{i18n_namespace}.form.map_skip_checkbox") %> - - <% end %> + <%= form.check_box :skip_map, + label: t("#{i18n_namespace}.form.map_skip_checkbox"), + class: "js-toggle-map" %>
<% end %> diff --git a/app/views/organizations/registrations/new.html.erb b/app/views/organizations/registrations/new.html.erb index db354259e..705f27fde 100644 --- a/app/views/organizations/registrations/new.html.erb +++ b/app/views/organizations/registrations/new.html.erb @@ -27,12 +27,14 @@ label: t("devise_views.organizations.registrations.new.password_confirmation_label"), placeholder: t("devise_views.organizations.registrations.new.password_confirmation_label") %> - <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t("devise_views.users.registrations.new.terms_title"), label: false %> - - <%= t("devise_views.users.registrations.new.terms", - terms: link_to(t("devise_views.users.registrations.new.terms_link"), "/conditions", title: t("shared.target_blank_html"), target: "_blank")).html_safe %> - <% end %> + <%= f.check_box :terms_of_service, + title: t("devise_views.users.registrations.new.terms_title"), + label: t("devise_views.users.registrations.new.terms", + terms: link_to(t("devise_views.users.registrations.new.terms_link"), + "/conditions", + title: t("shared.target_blank_html"), + target: "_blank") + ).html_safe %>
<%= f.submit t("devise_views.organizations.registrations.new.submit"), class: "button expanded" %> diff --git a/app/views/proposals/_form.html.erb b/app/views/proposals/_form.html.erb index d87385e20..7e20272f9 100644 --- a/app/views/proposals/_form.html.erb +++ b/app/views/proposals/_form.html.erb @@ -101,14 +101,12 @@
<% if @proposal.new_record? %> - <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %> - - <%= t("form.accept_terms", - policy: link_to(t("form.policy"), "/privacy", target: "blank"), - conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %> - - <% end %> + <%= f.check_box :terms_of_service, + title: t("form.accept_terms_title"), + label: t("form.accept_terms", + policy: link_to(t("form.policy"), "/privacy", target: "blank"), + conditions: link_to(t("form.conditions"), "/conditions", target: "blank") + ).html_safe %> <% end %>
diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 7309606a4..c97b1befb 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -36,15 +36,14 @@ <%= f.text_field :redeemable_code, placeholder: t("devise_views.users.registrations.new.redeemable_code") %> <% end %> - <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t("devise_views.users.registrations.new.terms_title"), label: false %> - - <%= t("devise_views.users.registrations.new.terms", - terms: link_to(t("devise_views.users.registrations.new.terms_link"), "/conditions", - title: t("shared.target_blank_html"), - target: "_blank")).html_safe %> - - <% end %> + <%= f.check_box :terms_of_service, + title: t("devise_views.users.registrations.new.terms_title"), + label: t("devise_views.users.registrations.new.terms", + terms: link_to(t("devise_views.users.registrations.new.terms_link"), "/conditions", + title: t("shared.target_blank_html"), + target: "_blank") + ).html_safe %> +
<%= f.submit t("devise_views.users.registrations.new.submit"), class: "button expanded" %>
diff --git a/app/views/valuation/budget_investments/_dossier_form.html.erb b/app/views/valuation/budget_investments/_dossier_form.html.erb index 60ec0e2d5..5f601b18b 100644 --- a/app/views/valuation/budget_investments/_dossier_form.html.erb +++ b/app/views/valuation/budget_investments/_dossier_form.html.erb @@ -75,14 +75,12 @@
- <%= f.label :valuation_finished do %> - <%= f.check_box :valuation_finished, - title: t("valuation.budget_investments.edit.valuation_finished"), - label: false, id: "js-investment-report-alert", - "data-alert": t("valuation.budget_investments.edit.valuation_finished_alert"), - "data-not-feasible-alert": t("valuation.budget_investments.edit.not_feasible_alert") %> - <%= t("valuation.budget_investments.edit.valuation_finished") %> - <% end %> + <%= f.check_box :valuation_finished, + label: t("valuation.budget_investments.edit.valuation_finished"), + label_options: { for: "js-investment-report-alert" }, + id: "js-investment-report-alert", + "data-alert": t("valuation.budget_investments.edit.valuation_finished_alert"), + "data-not-feasible-alert": t("valuation.budget_investments.edit.not_feasible_alert") %>
diff --git a/app/views/verification/residence/new.html.erb b/app/views/verification/residence/new.html.erb index c18d42ccc..9c9adb322 100644 --- a/app/views/verification/residence/new.html.erb +++ b/app/views/verification/residence/new.html.erb @@ -77,16 +77,13 @@
- <%= f.label :terms_of_service do %> - <%= f.check_box :terms_of_service, title: t("verification.residence.new.accept_terms_text_title"), label: false %> - - <%= t("verification.residence.new.accept_terms_text", - terms_url: link_to(t("verification.residence.new.terms"), "/census_terms", - title: t("shared.target_blank_html"), - target: "_blank")).html_safe - %> - - <% end %> + <%= f.check_box :terms_of_service, + title: t("verification.residence.new.accept_terms_text_title"), + label: t("verification.residence.new.accept_terms_text", + terms_url: link_to(t("verification.residence.new.terms"), "/census_terms", + title: t("shared.target_blank_html"), + target: "_blank") + ).html_safe %>
diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb index fd7a24c98..205339422 100644 --- a/lib/consul_form_builder.rb +++ b/lib/consul_form_builder.rb @@ -17,6 +17,16 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder end end + def check_box(attribute, options = {}) + if options[:label] != false + label = content_tag(:span, label_text(object, attribute, options[:label]), class: "checkbox") + + super(attribute, options.merge(label: label)) + else + super + end + end + private def label_with_hint(attribute, options) @@ -24,6 +34,14 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder help_text(attribute, options) end + def label_text(object, attribute, text) + if text.nil? || text == true + default_label_text(object, attribute) + else + text + end + end + def help_text(attribute, options) if options[:hint] content_tag :span, options[:hint], class: "help-text", id: help_text_id(attribute, options) From aec84f6522939e5c4fe0e91ee843208a60f7cafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Oct 2019 19:09:28 +0200 Subject: [PATCH 7/8] Generate labels `for` attribute automatically I'm not sure why it isn't already done by foundation's form builder. It doesn't make any sense to change an ID of a form field without changing the `for` attribute of its label. --- app/views/comments/_form.html.erb | 9 +++------ .../legislation/annotations/_comments_box.html.erb | 7 +++++-- app/views/tracking/progress_bars/_form.html.erb | 2 ++ .../budget_investments/_dossier_form.html.erb | 1 - lib/consul_form_builder.rb | 14 ++++++++++++-- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 40613b044..87b04c317 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -6,8 +6,7 @@ <%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment.body_max_length, - label: leave_comment_text(commentable), - label_options: { for: "comment-body-#{css_id}" } %> + label: leave_comment_text(commentable) %> <%= f.hidden_field :commentable_type, value: commentable.class.name %> <%= f.hidden_field :commentable_id, value: commentable.id %> @@ -20,16 +19,14 @@
<%= f.check_box :as_moderator, label: t("comments.form.comment_as_moderator"), - id: "comment-as-moderator-#{css_id}", - label_options: { for: "comment-as-moderator-#{css_id}" } %> + id: "comment-as-moderator-#{css_id}" %>
<% end %> <% if can? :comment_as_administrator, commentable %>
<%= f.check_box :as_administrator, label: t("comments.form.comment_as_admin"), - id: "comment-as-administrator-#{css_id}", - label_options: { for: "comment-as-administrator-#{css_id}" } %> + id: "comment-as-administrator-#{css_id}" %>
<% end %> diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index 7340f7e04..b9e8eea70 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -25,8 +25,11 @@ <% css_id = parent_or_commentable_dom_id(nil, annotation) %> diff --git a/app/views/tracking/progress_bars/_form.html.erb b/app/views/tracking/progress_bars/_form.html.erb index 4a66107d3..7606b17e8 100644 --- a/app/views/tracking/progress_bars/_form.html.erb +++ b/app/views/tracking/progress_bars/_form.html.erb @@ -19,8 +19,10 @@ <% progress_options = { min: ProgressBar::RANGE.min, max: ProgressBar::RANGE.max, step: 1 } %>
+ <%= f.label :percentage %> <%= f.text_field :percentage, { type: :range, id: "percentage_range", + label: false, class: "column" }.merge(progress_options) %>
diff --git a/app/views/valuation/budget_investments/_dossier_form.html.erb b/app/views/valuation/budget_investments/_dossier_form.html.erb index 5f601b18b..b7fea5574 100644 --- a/app/views/valuation/budget_investments/_dossier_form.html.erb +++ b/app/views/valuation/budget_investments/_dossier_form.html.erb @@ -77,7 +77,6 @@
<%= f.check_box :valuation_finished, label: t("valuation.budget_investments.edit.valuation_finished"), - label_options: { for: "js-investment-report-alert" }, id: "js-investment-report-alert", "data-alert": t("valuation.budget_investments.edit.valuation_finished_alert"), "data-not-feasible-alert": t("valuation.budget_investments.edit.not_feasible_alert") %> diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb index 205339422..b6064fbe2 100644 --- a/lib/consul_form_builder.rb +++ b/lib/consul_form_builder.rb @@ -9,7 +9,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder %i[text_field text_area cktext_area number_field password_field email_field].each do |field| define_method field do |attribute, options = {}| - label_with_hint(attribute, options) + + label_with_hint(attribute, options.merge(label_options: label_options_for(options))) + super(attribute, options.merge( label: false, hint: false, aria: { describedby: help_text_id(attribute, options) } @@ -21,7 +21,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder if options[:label] != false label = content_tag(:span, label_text(object, attribute, options[:label]), class: "checkbox") - super(attribute, options.merge(label: label)) + super(attribute, options.merge(label: label, label_options: label_options_for(options))) else super end @@ -42,6 +42,16 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder end end + def label_options_for(options) + label_options = options[:label_options] || {} + + if options[:id] + { for: options[:id] }.merge(label_options) + else + label_options + end + end + def help_text(attribute, options) if options[:hint] content_tag :span, options[:hint], class: "help-text", id: help_text_id(attribute, options) From 4f1131d2e5afe50271ca874770b3ede0709dcaf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 3 Oct 2019 20:43:13 +0200 Subject: [PATCH 8/8] Add labels to radio buttons automatically --- .../valuation/budget_investments/_dossier_form.html.erb | 9 +++------ config/locales/en/activerecord.yml | 3 +++ config/locales/en/valuation.yml | 3 --- config/locales/es/activerecord.yml | 3 +++ config/locales/es/valuation.yml | 3 --- lib/consul_form_builder.rb | 6 ++++++ 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/views/valuation/budget_investments/_dossier_form.html.erb b/app/views/valuation/budget_investments/_dossier_form.html.erb index b7fea5574..cb1230c18 100644 --- a/app/views/valuation/budget_investments/_dossier_form.html.erb +++ b/app/views/valuation/budget_investments/_dossier_form.html.erb @@ -7,22 +7,19 @@ <%= t("valuation.budget_investments.edit.feasibility") %>
- <%= f.radio_button :feasibility, "undecided", - label: t("valuation.budget_investments.edit.undefined_feasible") %> + <%= f.radio_button :feasibility, "undecided" %>
- <%= f.radio_button :feasibility, "feasible", - label: t("valuation.budget_investments.edit.feasible") %> + <%= f.radio_button :feasibility, "feasible" %>
- <%= f.radio_button :feasibility, "unfeasible", - label: t("valuation.budget_investments.edit.unfeasible") %> + <%= f.radio_button :feasibility, "unfeasible" %>
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index f63161e4b..62ba0b9eb 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -153,6 +153,9 @@ en: organization_name: "If you are proposing in the name of a collective/organization, or on behalf of more people, write its name" image: "Proposal descriptive image" image_title: "Image title" + feasibility_feasible: "Feasible" + feasibility_undecided: "Undefined" + feasibility_unfeasible: "Unfeasible" budget/investment/translation: title: "Title" description: "Description" diff --git a/config/locales/en/valuation.yml b/config/locales/en/valuation.yml index 2c8c6d7c2..9153fe244 100644 --- a/config/locales/en/valuation.yml +++ b/config/locales/en/valuation.yml @@ -60,9 +60,6 @@ en: price_first_year_html: "Cost during the first year (%{currency}) (optional, data not public)" price_explanation_html: Price explanation feasibility: Feasibility - feasible: Feasible - unfeasible: Not feasible - undefined_feasible: Pending feasible_explanation_html: Feasibility explanation valuation_finished: Valuation finished valuation_finished_alert: "Are you sure you want to mark this report as completed? If you do it, it can no longer be modified." diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 87f4b19be..e7ea7d05d 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -155,6 +155,9 @@ es: organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre" image: "Imagen descriptiva del proyecto de gasto" image_title: "Título de la imagen" + feasibility_feasible: "Viable" + feasibility_undecided: "Sin decidir" + feasibility_unfeasible: "Inviable" budget/investment/translation: title: "Título" description: "Descripción" diff --git a/config/locales/es/valuation.yml b/config/locales/es/valuation.yml index 15d6b7c31..bf4ff09e2 100644 --- a/config/locales/es/valuation.yml +++ b/config/locales/es/valuation.yml @@ -60,9 +60,6 @@ es: price_first_year_html: "Coste en el primer año (%{currency}) (opcional, dato no público)" price_explanation_html: Informe de coste (opcional, dato público) feasibility: Viabilidad - feasible: Viable - unfeasible: Inviable - undefined_feasible: Sin decidir feasible_explanation_html: Informe de inviabilidad (en caso de que lo sea, dato público) valuation_finished: Informe finalizado valuation_finished_alert: "¿Estás seguro/a de querer marcar este informe como completado? Una vez hecho, no se puede deshacer la acción." diff --git a/lib/consul_form_builder.rb b/lib/consul_form_builder.rb index b6064fbe2..9cf822823 100644 --- a/lib/consul_form_builder.rb +++ b/lib/consul_form_builder.rb @@ -27,6 +27,12 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder end end + def radio_button(attribute, tag_value, options = {}) + default_label = object.class.human_attribute_name("#{attribute}_#{tag_value}") + + super(attribute, tag_value, { label: default_label }.merge(options)) + end + private def label_with_hint(attribute, options)