Simplify generating checkboxes in forms
Using the block syntax to generate the label with a <span> tag inside isn't necessary after upgrading foundation_rails_helpers. Before the upgrade, we couldn't do so because the <span> tag was escaped.
This commit is contained in:
@@ -32,82 +32,40 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :public_activity do %>
|
||||
<%= f.check_box :public_activity, title: t("account.show.public_activity_label"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.public_activity_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :public_activity, label: t("account.show.public_activity_label") %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :public_interests do %>
|
||||
<%= f.check_box :public_interests, title: t("account.show.public_interests_label"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.public_interests_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :public_interests, label: t("account.show.public_interests_label") %>
|
||||
</div>
|
||||
|
||||
<% if @account.email.present? %>
|
||||
<h2><%= t("account.show.notifications") %></h2>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_on_comment do %>
|
||||
<%= f.check_box :email_on_comment, title: t("account.show.email_on_comment_label"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :email_on_comment, label: t("account.show.email_on_comment_label") %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= 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 %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_comment_reply_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :email_on_comment_reply, label: t("account.show.email_on_comment_reply_label") %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_newsletter_subscribed do %>
|
||||
<%= f.check_box :newsletter, title: t("account.show.subscription_to_website_newsletter_label"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.subscription_to_website_newsletter_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :newsletter, label: t("account.show.subscription_to_website_newsletter_label") %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= f.label :email_digest do %>
|
||||
<%= f.check_box :email_digest, title: t("account.show.email_digest_label"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_digest_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :email_digest, label: t("account.show.email_digest_label") %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= 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 %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.email_on_direct_message_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :email_on_direct_message, label: t("account.show.email_on_direct_message_label") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if @account.official_level == 1 %>
|
||||
<div>
|
||||
<%= f.label :official_position_badge do %>
|
||||
<%= f.check_box :official_position_badge,
|
||||
title: t("account.show.official_position_badge_label"),
|
||||
label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.official_position_badge_label") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :official_position_badge, label: t("account.show.official_position_badge_label") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -116,23 +74,13 @@
|
||||
|
||||
<% if feature?("user.recommendations_on_debates") %>
|
||||
<div>
|
||||
<%= f.label :recommended_debates do %>
|
||||
<%= f.check_box :recommended_debates, title: t("account.show.show_debates_recommendations"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.show_debates_recommendations") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :recommended_debates, label: t("account.show.show_debates_recommendations") %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if feature?("user.recommendations_on_proposals") %>
|
||||
<div>
|
||||
<%= f.label :recommended_proposals do %>
|
||||
<%= f.check_box :recommended_proposals, title: t("account.show.show_proposals_recommendations"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("account.show.show_proposals_recommendations") %>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= f.check_box :recommended_proposals, label: t("account.show.show_proposals_recommendations") %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -105,18 +105,16 @@
|
||||
<% if @investment.incompatible? || @investment.winner? %>
|
||||
<div class="small-12 medium-3 column">
|
||||
<h2 id="incompatible"><%= t("admin.budget_investments.edit.compatibility") %></h2>
|
||||
<%= f.label :incompatible do %>
|
||||
<%= f.check_box :incompatible, title: t("admin.budget_investments.edit.compatibility"), label: false %>
|
||||
<span class="checkbox"><%= t("admin.budget_investments.edit.mark_as_incompatible") %></span>
|
||||
<% end %>
|
||||
<%= f.check_box :incompatible,
|
||||
title: t("admin.budget_investments.edit.compatibility"),
|
||||
label: t("admin.budget_investments.edit.mark_as_incompatible") %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="small-12 medium-3 column float-left">
|
||||
<h2 id="selected"><%= t("admin.budget_investments.edit.selection") %></h2>
|
||||
<%= f.label :selected do %>
|
||||
<%= f.check_box :selected, title: t("admin.budget_investments.edit.selection"), label: false %>
|
||||
<span class="checkbox"><%= t("admin.budget_investments.edit.mark_as_selected") %></span>
|
||||
<% end %>
|
||||
<%= f.check_box :selected,
|
||||
title: t("admin.budget_investments.edit.selection"),
|
||||
label: t("admin.budget_investments.edit.mark_as_selected") %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -89,14 +89,11 @@
|
||||
<% unless current_user.manager? %>
|
||||
|
||||
<div class="small-12 column">
|
||||
<%= f.label :terms_of_service do %>
|
||||
<%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("form.accept_terms",
|
||||
<%= 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 %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
@@ -18,14 +18,18 @@
|
||||
|
||||
<% if can? :comment_as_moderator, commentable %>
|
||||
<div class="float-right">
|
||||
<%= 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}" } %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if can? :comment_as_administrator, commentable %>
|
||||
<div class="float-right">
|
||||
<%= 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}" } %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -35,14 +35,12 @@
|
||||
</div>
|
||||
<div class="small-12 column">
|
||||
<% if @debate.new_record? %>
|
||||
<%= f.label :terms_of_service do %>
|
||||
<%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("form.accept_terms",
|
||||
<%= 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 %>
|
||||
</span>
|
||||
<% end %>
|
||||
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")
|
||||
).html_safe %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -21,10 +21,7 @@
|
||||
|
||||
<% if devise_mapping.rememberable? -%>
|
||||
<div class="small-12 column">
|
||||
<%= f.label :remember_me do %>
|
||||
<%= f.check_box :remember_me, title: t("devise_views.sessions.new.remember_me"), label: false %>
|
||||
<span class="checkbox"><%= t("devise_views.sessions.new.remember_me") %></span>
|
||||
<% end %>
|
||||
<%= f.check_box :remember_me, label: t("devise_views.sessions.new.remember_me") %>
|
||||
</div>
|
||||
<% end -%>
|
||||
|
||||
|
||||
@@ -69,14 +69,12 @@
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if @proposal.new_record? %>
|
||||
<%= f.label :terms_of_service do %>
|
||||
<%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("form.accept_terms",
|
||||
<%= 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 %>
|
||||
</span>
|
||||
<% end %>
|
||||
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")
|
||||
).html_safe %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -18,14 +18,8 @@
|
||||
id: map_location_input_id(parent_class, "zoom") %>
|
||||
|
||||
<div>
|
||||
<%= form.label :skip_map do %>
|
||||
<%= form.check_box :skip_map,
|
||||
title: t("#{i18n_namespace}.form.map_skip_checkbox"),
|
||||
label: false,
|
||||
label: t("#{i18n_namespace}.form.map_skip_checkbox"),
|
||||
class: "js-toggle-map" %>
|
||||
<span class="checkbox">
|
||||
<%= t("#{i18n_namespace}.form.map_skip_checkbox") %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -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 %>
|
||||
<span class="checkbox">
|
||||
<%= 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 %></span>
|
||||
<% 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 %>
|
||||
|
||||
<div class="small-12 medium-6 small-centered">
|
||||
<%= f.submit t("devise_views.organizations.registrations.new.submit"), class: "button expanded" %>
|
||||
|
||||
@@ -101,14 +101,12 @@
|
||||
|
||||
<div class="small-12 column">
|
||||
<% if @proposal.new_record? %>
|
||||
<%= f.label :terms_of_service do %>
|
||||
<%= f.check_box :terms_of_service, title: t("form.accept_terms_title"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("form.accept_terms",
|
||||
<%= 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 %>
|
||||
</span>
|
||||
<% end %>
|
||||
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")
|
||||
).html_safe %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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 %>
|
||||
<span class="checkbox">
|
||||
<%= t("devise_views.users.registrations.new.terms",
|
||||
<%= 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 %>
|
||||
</span>
|
||||
<% end %>
|
||||
target: "_blank")
|
||||
).html_safe %>
|
||||
|
||||
<div class="small-12 medium-6 small-centered">
|
||||
<%= f.submit t("devise_views.users.registrations.new.submit"), class: "button expanded" %>
|
||||
</div>
|
||||
|
||||
@@ -75,14 +75,12 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= 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",
|
||||
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") %>
|
||||
<span class="checkbox"><%= t("valuation.budget_investments.edit.valuation_finished") %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -77,16 +77,13 @@
|
||||
</div>
|
||||
|
||||
<div class="small-12">
|
||||
<%= f.label :terms_of_service do %>
|
||||
<%= f.check_box :terms_of_service, title: t("verification.residence.new.accept_terms_text_title"), label: false %>
|
||||
<span class="checkbox">
|
||||
<%= t("verification.residence.new.accept_terms_text",
|
||||
<%= 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
|
||||
%>
|
||||
</span>
|
||||
<% end %>
|
||||
target: "_blank")
|
||||
).html_safe %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 clear">
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user