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.
This commit is contained in:
@@ -95,30 +95,8 @@ module TranslatableFormHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
class TranslationsFieldsBuilder < ConsulFormBuilder
|
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
|
def locale
|
||||||
@object.locale
|
@object.locale
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,30 +24,20 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<%= f.translatable_fields do |translations_form| %>
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= f.label :description, t("admin.budget_phases.edit.description") %>
|
|
||||||
|
|
||||||
<span class="help-text" id="phase-description-help-text">
|
|
||||||
<%= t("admin.budget_phases.edit.description_help_text") %>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<div class="ckeditor">
|
<div class="ckeditor">
|
||||||
<%= translations_form.cktext_area :description,
|
<%= translations_form.cktext_area :description,
|
||||||
maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH,
|
maxlength: Budget::Phase::DESCRIPTION_MAX_LENGTH,
|
||||||
label: false %>
|
label: t("admin.budget_phases.edit.description"),
|
||||||
|
hint: t("admin.budget_phases.edit.description_help_text") %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= f.label :summary, t("admin.budget_phases.edit.summary") %>
|
|
||||||
|
|
||||||
<span class="help-text" id="phase-summary-help-text">
|
|
||||||
<%= t("admin.budget_phases.edit.summary_help_text") %>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<div class="ckeditor">
|
<div class="ckeditor">
|
||||||
<%= translations_form.cktext_area :summary,
|
<%= translations_form.cktext_area :summary,
|
||||||
maxlength: Budget::Phase::SUMMARY_MAX_LENGTH,
|
maxlength: Budget::Phase::SUMMARY_MAX_LENGTH,
|
||||||
label: false %>
|
label: t("admin.budget_phases.edit.summary"),
|
||||||
|
hint: t("admin.budget_phases.edit.summary_help_text") %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -47,21 +47,18 @@
|
|||||||
|
|
||||||
<div class="row expanded margin-top">
|
<div class="row expanded margin-top">
|
||||||
<div class="small-12 medium-4 column">
|
<div class="small-12 medium-4 column">
|
||||||
<%= f.label :day_offset %>
|
<%= f.number_field :day_offset, step: 1, min: 0,
|
||||||
<p class="help-text"><%= t("admin.dashboard.actions.form.help_text") %></p>
|
hint: t("admin.dashboard.actions.form.help_text") %>
|
||||||
<%= f.number_field :day_offset, label: false, step: 1, min: 0 %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-4 column">
|
<div class="small-12 medium-4 column">
|
||||||
<%= f.label :required_supports %>
|
<%= f.number_field :required_supports, step: 1, min: 0,
|
||||||
<p class="help-text"><%= t("admin.dashboard.actions.form.help_text") %></p>
|
hint: t("admin.dashboard.actions.form.help_text") %>
|
||||||
<%= f.number_field :required_supports, label: false, step: 1, min: 0 %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-4 column">
|
<div class="small-12 medium-4 column">
|
||||||
<%= f.label :order %>
|
<%= f.number_field :order, step: 1, min: 0,
|
||||||
<p class="help-text"><%= t("admin.dashboard.actions.form.help_text") %></p>
|
hint: t("admin.dashboard.actions.form.help_text") %>
|
||||||
<%= f.number_field :order, label: false, step: 1, min: 0 %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -8,22 +8,16 @@
|
|||||||
|
|
||||||
<div class="clear">
|
<div class="clear">
|
||||||
<div class="small-12 medium-6 large-4 column">
|
<div class="small-12 medium-6 large-4 column">
|
||||||
<%= f.label :census_code %>
|
<%= f.text_field :census_code, hint: t("admin.geozones.geozone.code_help") %>
|
||||||
<p class="help-text"><%= t("admin.geozones.geozone.code_help") %></p>
|
|
||||||
<%= f.text_field :census_code, label: false %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-6 large-4 column end">
|
<div class="small-12 medium-6 large-4 column end">
|
||||||
<%= f.label :external_code %>
|
<%= f.text_field :external_code, hint: t("admin.geozones.geozone.code_help") %>
|
||||||
<p class="help-text"><%= t("admin.geozones.geozone.code_help") %></p>
|
|
||||||
<%= f.text_field :external_code, label: false %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 large-8 column">
|
<div class="small-12 large-8 column">
|
||||||
<%= f.label :html_map_coordinates %>
|
<%= f.text_field :html_map_coordinates, hint: t("admin.geozones.geozone.coordinates_help") %>
|
||||||
<p class="help-text"><%= t("admin.geozones.geozone.coordinates_help") %></p>
|
|
||||||
<%= f.text_field :html_map_coordinates, label: false %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
|
|||||||
@@ -16,10 +16,9 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="small-12 medium-8 column">
|
<div class="small-12 medium-8 column">
|
||||||
<%= f.label :custom_list, t("admin.legislation.proposals.form.custom_categories") %>
|
|
||||||
<span class="help-text"><%= t("admin.legislation.proposals.form.custom_categories_description") %></span>
|
|
||||||
<%= f.text_field :custom_list, value: @process.tag_list_on(:customs).to_s,
|
<%= 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"),
|
placeholder: t("admin.legislation.proposals.form.custom_categories_placeholder"),
|
||||||
class: "js-tag-list",
|
class: "js-tag-list",
|
||||||
aria: { describedby: "tag-list-help-text" } %>
|
aria: { describedby: "tag-list-help-text" } %>
|
||||||
|
|||||||
@@ -14,10 +14,8 @@
|
|||||||
<%= f.text_field :signable_id %>
|
<%= f.text_field :signable_id %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= f.label :required_fields_to_verify %>
|
<%= f.text_area :required_fields_to_verify, rows: "6",
|
||||||
<p class="help-text" id="required-fields-to-verify-help-text"><%= required_fields_to_verify_text_help %></p>
|
hint: sanitize("#{required_fields_to_verify_text_help}<br/>#{example_text_help}") %>
|
||||||
<p class="help-text"> <%= example_text_help %></p>
|
|
||||||
<%= f.text_area :required_fields_to_verify, rows: "6", label: false, aria: { describedby: "required-fields-to-verify-help-text" } %>
|
|
||||||
|
|
||||||
<%= f.submit(class: "button", value: t("admin.signature_sheets.new.submit")) %>
|
<%= f.submit(class: "button", value: t("admin.signature_sheets.new.submit")) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -32,9 +32,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<%= f.label :slug %>
|
<%= f.text_field :slug, size: 80, maxlength: 80,
|
||||||
<p class="help-text"><%= t("admin.site_customization.pages.new.slug_help_html") %>
|
hint: t("admin.site_customization.pages.new.slug_help_html") %>
|
||||||
<%= f.text_field :slug, label: false, size: 80, maxlength: 80 %>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
|
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 = {})
|
def enum_select(attribute, options = {}, html_options = {})
|
||||||
choices = object.class.send(attribute.to_s.pluralize).keys.map do |name|
|
choices = object.class.send(attribute.to_s.pluralize).keys.map do |name|
|
||||||
[object.class.human_attribute_name("#{attribute}.#{name}"), name]
|
[object.class.human_attribute_name("#{attribute}.#{name}"), name]
|
||||||
@@ -12,4 +6,24 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
|
|||||||
|
|
||||||
select attribute, choices, options, html_options
|
select attribute, choices, options, html_options
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user