diff --git a/config/initializers/simple_form.rb b/config/initializers/simple_form.rb index 63a6e5f0..44e73c25 100644 --- a/config/initializers/simple_form.rb +++ b/config/initializers/simple_form.rb @@ -5,7 +5,8 @@ # wrapper, change the order or even add your own to the # stack. The options given below are used to wrap the # whole input. - config.wrappers :default, :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b| + config.wrappers :default, class: :input, + hint_class: :field_with_hint, error_class: :field_with_errors do |b| ## Extensions enabled by default # Any of these extensions can be disabled for a # given input by passing: `f.input EXTENSION_NAME => false`. @@ -17,7 +18,7 @@ b.use :html5 # Calculates placeholders automatically from I18n - # You can also pass a string as f.input :placeholder => "Placeholder" + # You can also pass a string as f.input placeholder: "Placeholder" b.use :placeholder ## Optional extensions @@ -40,152 +41,125 @@ ## Inputs b.use :label_input - b.use :hint, :wrap_with => { :tag => :span, :class => :hint } - b.use :error, :wrap_with => { :tag => :span, :class => :error } + b.use :hint, wrap_with: { tag: :span, class: :hint } + b.use :error, wrap_with: { tag: :span, class: :error } end - config.wrappers :bootstrap, :tag => 'div', :class => 'form-group', :error_class => 'has-error' do |b| + config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder b.use :label, class: 'control-label' - b.wrapper :tag => 'div' do |ba| + b.wrapper tag: 'div' do |ba| ba.use :input, class: 'form-control' - ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :vertical_file_input, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b| + config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder b.use :label, class: 'control-label' - b.wrapper :tag => 'div' do |ba| + b.wrapper tag: 'div' do |ba| ba.use :input - ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :vertical_check_box, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b| + config.wrappers :vertical_check_box, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder - b.wrapper :tag => 'div', :class => 'checkbox' do |ba| + b.wrapper tag: 'div', class: 'checkbox' do |ba| ba.use :label_input end - b.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - b.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + b.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end - config.wrappers :vertical_radio_button, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b| + config.wrappers :vertical_radio_button, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder b.use :label_input - b.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - b.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + b.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end - config.wrappers :bootstrap_horizontal, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b| + config.wrappers :bootstrap_horizontal, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder - b.use :label, :class => 'col-sm-3 control-label' + b.use :label, class: 'col-sm-3 control-label' - b.wrapper :tag => 'div', :class => 'col-sm-9' do |ba| + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| ba.use :input, class: 'form-control' - ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :horizontal_file_input, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b| + config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder - b.use :label, :class => 'col-sm-3 control-label' + b.use :label, class: 'col-sm-3 control-label' - b.wrapper :tag => 'div', :class => 'col-sm-9' do |ba| + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| ba.use :input - ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :horizontal_check_box, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b| + config.wrappers :horizontal_check_box, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder - b.wrapper :tag => 'div', :class => 'col-sm-offset-3 col-sm-9' do |wr| - wr.wrapper :tag => 'div', :class => 'checkbox' do |ba| - ba.use :label_input, :class => 'col-sm-9' + b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr| + wr.wrapper tag: 'div', class: 'checkbox' do |ba| + ba.use :label_input, class: 'col-sm-9' end - wr.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - wr.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + wr.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + wr.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :horizontal_radio_button, :tag => 'div', :class => 'form-group', :error_class => 'error' do |b| + config.wrappers :horizontal_radio_button, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| b.use :html5 b.use :placeholder - b.use :label, :class => 'col-sm-3 control-label' + b.use :label, class: 'col-sm-3 control-label' - b.wrapper :tag => 'div', :class => 'col-sm-9' do |ba| + b.wrapper tag: 'div', class: 'col-sm-9' do |ba| ba.use :input - ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' } + ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' } + ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' } end end - config.wrappers :prepend, :tag => 'div', :class => "form-group", :error_class => 'error' do |b| - b.use :html5 - b.use :placeholder - b.use :label - b.wrapper :tag => 'div', :class => 'controls' do |input| - input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend| - prepend.use :input - end - input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' } - input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - end - end - - config.wrappers :append, :tag => 'div', :class => "form-group", :error_class => 'error' do |b| - b.use :html5 - b.use :placeholder - b.use :label - b.wrapper :tag => 'div', :class => 'controls' do |input| - input.wrapper :tag => 'div', :class => 'input-append' do |append| - append.use :input - end - input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' } - input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' } - end - end - - # Wrappers for forms and inputs using the Twitter Bootstrap toolkit. - # Check the Bootstrap docs (http://twitter.github.com/bootstrap) - # to learn about the different styles for forms and inputs, - # buttons and other elements. + # The default wrapper to be used by the FormBuilder. config.default_wrapper = :bootstrap # Define the way to render check boxes / radio buttons with labels. # Defaults to :nested for bootstrap config. - # :inline => input + label - # :nested => label > input + # inline: input + label + # nested: label > input config.boolean_style = :nested # Default class for buttons config.button_class = 'btn btn-default' - # Method used to tidy up errors. + # Method used to tidy up errors. Specify any Rails Array method. + # :first lists the first message for each field. + # Use :to_sentence to list all errors for each field. # config.error_method = :first # Default tag used for error notification helper. config.error_notification_tag = :div # CSS class to add for error notification helper. - # config.error_notification_class = 'alert alert-error' + config.error_notification_class = 'alert alert-error' # ID to add for error notification helper. # config.error_notification_id = nil @@ -214,9 +188,7 @@ # config.label_text = lambda { |label, required| "#{required} #{label}" } # You can define the class to use on all labels. Default is nil. - # config.label_class = 'control-label' - # config.input_class = 'form-control' - config.boolean_label_class = nil + # config.label_class = nil # You can define the class to use on all forms. Default is simple_form. # config.form_class = :simple_form @@ -227,8 +199,11 @@ # Whether attributes are required by default (or not). Default is true. # config.required_by_default = true - # Tell browsers whether to use default HTML5 validations (novalidate option). - # Default is enabled. + # Tell browsers whether to use the native HTML5 validations (novalidate form option). + # These validations are enabled in SimpleForm's internal config but disabled by default + # in this configuration, which is recommended due to some quirks from different browsers. + # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations, + # change this configuration to true. config.browser_validations = false # Collection of methods to detect if a file type was given. @@ -239,15 +214,16 @@ # matches the regexp as value. # config.input_mappings = { /count/ => :integer } + # Custom wrappers for input types. This should be a hash containing an input + # type as key and the wrapper that will be used for all inputs with specified type. + # config.wrapper_mappings = { string: :prepend } + # Default priority for time_zone inputs. # config.time_zone_priority = nil # Default priority for country inputs. # config.country_priority = nil - # Default size for text inputs. - # config.default_input_size = 50 - # When false, do not use translations for labels. # config.translate_labels = true @@ -256,4 +232,14 @@ # Cache SimpleForm inputs discovery # config.cache_discovery = !Rails.env.development? + + # Default class for inputs + # config.input_class = nil + + # Define the default class of the input wrapper of the boolean input. + config.boolean_label_class = nil + + # Defines if the default input wrapper class should be included in radio + # collection wrappers. + # config.include_default_input_wrapper_class = true end diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index dcf0ebf7..e1329285 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -1,16 +1,5 @@ en: simple_form: - hints: - article: - my_email: Lorem ipsum dolor sit amet - my_password: Lorem ipsum dolor sit amet - my_file: Example block-level help text here. - my_checkbox: Lorem ipsum dolor sit amet - my_radio_buttons: Lorem ipsum dolor sit amet - placeholders: - user: - username: 'Your username' - password: '****' "yes": 'Yes' "no": 'No' required: @@ -20,16 +9,24 @@ en: # When using html, text and mark won't be used. # html: '*' error_notification: - default_message: "Some errors were found, please take a look:" + default_message: "Please review the problems below:" # Labels and hints examples # labels: - # password: 'Password' + # defaults: + # password: 'Password' # user: # new: - # email: 'E-mail para efetuar o sign in.' + # email: 'E-mail to sign in.' # edit: # email: 'E-mail.' - # hints: - # username: 'User name to sign in.' - # password: 'No special characters, please.' - + hints: + article: + my_email: Lorem ipsum dolor sit amet + my_password: Lorem ipsum dolor sit amet + my_file: Example block-level help text here. + my_checkbox: Lorem ipsum dolor sit amet + my_radio_buttons: Lorem ipsum dolor sit amet + placeholders: + user: + username: 'Your username' + password: '****'