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