Last active
July 8, 2020 08:34
-
-
Save sowenjub/ab558d893c5004d3c175e6817c066355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= f.label :email, required: true, class: "block text-xxs uppercase text-gray-500" do |label_builder| | |
= label_builder.translation | |
span.ml-2.normal-case.text-orange-400.text-xxs.font-semibold= t("required") | |
= f.email_field :email, autocomplete: false, required: true, class: "form-input mt-1 block w-full text-field focus:shadow-outline focus:border-green-300", placeholder: "[email protected]" | |
# Or with the form builder | |
= f.label :email, required: true, class: "block text-xxs uppercase text-gray-500", required_class: "ml-2 normal-case text-orange-400 text-xxs font-semibold" | |
= f.email_field :email, autocomplete: false, required: true, class: "form-input mt-1 block w-full text-field focus:shadow-outline focus:border-green-300", placeholder: "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= f.label :email, required: true, class: "block text-xxs uppercase text-gray-500" do | |
= f.object.class.human_attribute_name(:email) | |
span.ml-2.normal-case.text-orange-400.text-xxs.font-semibold= t("required") | |
= f.email_field :email, autocomplete: false, required: true, class: "form-input mt-1 block w-full text-field focus:shadow-outline focus:border-green-300", placeholder: "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= f.label :email, required: true, class: "block text-xxs uppercase text-gray-500" | |
= f.email_field :email, autocomplete: false, required: true, class: "form-input mt-1 block w-full text-field focus:shadow-outline focus:border-green-300", placeholder: "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In case you want to put that in a form builder | |
class RequiringFormBuilder < ActionView::Helpers::FormBuilder | |
def label(method, text = nil, options = {}, &block) | |
text_is_options = text.is_a?(Hash) | |
required = text_is_options ? text[:required] : options[:required] | |
if required | |
required_class = text_is_options ? text.delete(:required_class) : options.delete(:required_class) | |
super(method, text, options) do |label_builder| | |
@template.concat label_builder.translation | |
@template.concat @template.content_tag(:span, I18n.t("required", scope: :helpers), class: required_class) | |
@template.concat(@template.capture(label_builder, &block)) if block_given? | |
end | |
else | |
super(method, text, options, &block) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment