Advertisement
Guest User

initializer/simple_form.rb

a guest
Apr 7th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 10.35 KB | None | 0 0
  1. # Use this setup block to configure all options available in SimpleForm.
  2. SimpleForm.setup do |config|
  3.   # Components used by the form builder to generate a complete input. You can remove
  4.   # any of them, change the order, or even add your own components to the stack.
  5.   # config.components = [ :placeholder, :label_input, :hint, :error ]
  6.   # config.components = [ :placeholder, :holdsport_label_input, :hint, :error ]
  7.  
  8.   # Default tag used on hints.
  9.   # config.hint_tag = :span
  10.  
  11.   # CSS class to add to all hint tags.
  12.   # config.hint_class = :hint
  13.  
  14.   # CSS class used on errors.
  15.   # config.error_class = :error
  16.  
  17.   # Default tag used on errors.
  18.   # config.error_tag = :span
  19.  
  20.   # Method used to tidy up errors.
  21.   # config.error_method = :first
  22.  
  23.   # Default tag used for error notification helper.
  24.   config.error_notification_tag = :div
  25.  
  26.   # CSS class to add for error notification helper.
  27.   # config.error_notification_class = :error_notification
  28.  
  29.   # ID to add for error notification helper.
  30.   # config.error_notification_id = nil
  31.  
  32.   # You can wrap all inputs in a pre-defined tag.
  33.   # config.wrapper_tag = nil
  34.  
  35.   # CSS class to add to all wrapper tags.
  36.   # config.wrapper_class = :input
  37.  
  38.   # CSS class to add to the wrapper if the field has errors.
  39.   # config.wrapper_error_class = :field_with_errors
  40.  
  41.   # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
  42.   # config.collection_wrapper_tag = nil
  43.  
  44.   # You can wrap each item in a collection of radio/check boxes with a tag, defaulting to span.
  45.   # config.item_wrapper_tag = :span
  46.  
  47.   # Series of attempts to detect a default label method for collection.
  48.   # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
  49.  
  50.   # Series of attempts to detect a default value method for collection.
  51.   # config.collection_value_methods = [ :id, :to_s ]
  52.  
  53.   # How the label text should be generated altogether with the required text.
  54.   # config.label_text = lambda { |label, required| "#{required} #{label}" }
  55.  
  56.   # You can define the class to use on all forms. Default is simple_form.
  57.   # config.form_class = :simple_form
  58.  
  59.   # Whether attributes are required by default (or not). Default is true.
  60.   # config.required_by_default = true
  61.  
  62.   # Tell browsers whether to use default HTML5 validations (novalidate option).
  63.   # Default is enabled.
  64.   config.browser_validations = false
  65.  
  66.   # Determines whether HTML5 types (:email, :url, :search, :tel) and attributes
  67.   # (e.g. required) are used or not. True by default.
  68.   # Having this on in non-HTML5 compliant sites can cause odd behavior in
  69.   # HTML5-aware browsers such as Chrome.
  70.   # config.html5 = true
  71.  
  72.   # Custom mappings for input types. This should be a hash containing a regexp
  73.   # to match as key, and the input type that will be used when the field name
  74.   # matches the regexp as value.
  75.   # config.input_mappings = { /count/ => :integer }
  76.  
  77.   # Collection of methods to detect if a file type was given.
  78.   # config.file_methods = [ :mounted_as, :file?, :public_filename ]
  79.  
  80.   # Default priority for time_zone inputs.
  81.   # config.time_zone_priority = nil
  82.  
  83.   # Default priority for country inputs.
  84.   # config.country_priority = nil
  85.  
  86.   # Default size for text inputs.
  87.   # config.default_input_size = 50
  88.  
  89.   # When false, do not use translations for labels, hints or placeholders.
  90.   # config.translate = true
  91.  
  92.   config.wrappers :default, :class => :input, :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
  93.     ## Extensions enabled by default
  94.     # Any of these extensions can be disabled for a
  95.     # given input by passing: `f.input EXTENSION_NAME => false`.
  96.     # You can make any of these extensions optional by
  97.     # renaming `b.use` to `b.optional`.
  98.  
  99.     # Determines whether to use HTML5 (:email, :url, ...)
  100.     # and required attributes
  101.     b.use :html5
  102.  
  103.     # Calculates placeholders automatically from I18n
  104.     # You can also pass a string as f.input :placeholder => "Placeholder"
  105.     b.use :placeholder
  106.  
  107.     ## Optional extensions
  108.     # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
  109.     # to the input. If so, they will retrieve the values from the model
  110.     # if any exists. If you want to enable the lookup for any of those
  111.     # extensions by default, you can change `b.optional` to `b.use`.
  112.  
  113.     # Calculates maxlength from length validations for string inputs
  114.     b.optional :maxlength
  115.  
  116.     # Calculates pattern from format validations for string inputs
  117.     b.optional :pattern
  118.  
  119.     # Calculates min and max from length validations for numeric inputs
  120.     b.optional :min_max
  121.  
  122.     # Calculates readonly automatically from readonly attributes
  123.     b.optional :readonly
  124.  
  125.     ## Inputs
  126.     b.use :label_input
  127.     b.use :hint,  :wrap_with => { :tag => :span, :class => :hint }
  128.     b.use :error, :wrap_with => { :tag => :span, :class => :error }
  129.   end
  130.  
  131.   config.wrappers :jquery_mobile, :tag => false do |b|
  132.     b.use :html5
  133.     b.use :placeholder
  134.     b.use :label
  135.     b.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
  136.     b.use :hint,  :wrap_with => { :tag => 'span', :class => 'help-block' }
  137.     b.use :input
  138.   end
  139.  
  140.   #########################################################
  141.   ####################### Bootstrap #######################
  142.   #########################################################
  143.  
  144.   ######### Config #########
  145.   config.button_class = 'btn btn-default'
  146.   #config.boolean_label_class = nil # This option doesn't exist in simple_form 2.1
  147.  
  148.   # Define the way to render check boxes / radio buttons with labels.
  149.   # Defaults to :nested for bootstrap config.
  150.   #   :inline => input + label
  151.   #   :nested => label > input
  152.   config.boolean_style = :nested
  153.  
  154.   # You can define the class to use on all labels. Default is nil.
  155.   config.label_class = 'control-label'
  156.  
  157.   ######### Wrappers #########
  158.   config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  159.     b.use :judge
  160.     b.use :html5
  161.     b.use :placeholder
  162.     b.use :label, class: 'control-label'
  163.  
  164.     b.wrapper tag: 'div' do |ba|
  165.       ba.use :input, class: 'form-control'
  166.       ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  167.       ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  168.     end
  169.   end
  170.  
  171.   config.wrappers :vertical_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  172.     b.use :judge
  173.     b.use :html5
  174.     b.use :placeholder
  175.     b.use :label, class: 'control-label'
  176.  
  177.     b.wrapper tag: 'div' do |ba|
  178.       ba.use :input
  179.       ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  180.       ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  181.     end
  182.   end
  183.  
  184.   config.wrappers :vertical_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  185.     b.use :judge
  186.     b.use :html5
  187.     b.use :placeholder
  188.  
  189.     b.wrapper tag: 'div', class: 'checkbox' do |ba|
  190.       ba.use :label_input
  191.     end
  192.  
  193.     b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  194.     b.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  195.   end
  196.  
  197.   config.wrappers :vertical_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  198.     b.use :judge
  199.     b.use :html5
  200.     b.use :placeholder
  201.     b.use :label_input
  202.     b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  203.     b.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  204.   end
  205.  
  206.   config.wrappers :horizontal_form, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  207.     b.use :judge
  208.     b.use :html5
  209.     b.use :placeholder
  210.     b.use :label, class: 'col-sm-3 control-label'
  211.  
  212.     b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
  213.       ba.use :input, class: 'form-control'
  214.       ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  215.       ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  216.     end
  217.   end
  218.  
  219.   config.wrappers :horizontal_file_input, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  220.     b.use :judge
  221.     b.use :html5
  222.     b.use :placeholder
  223.     b.use :label, class: 'col-sm-3 control-label'
  224.  
  225.     b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
  226.       ba.use :input
  227.       ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  228.       ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  229.     end
  230.   end
  231.  
  232.   config.wrappers :horizontal_boolean, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  233.     b.use :judge
  234.     b.use :html5
  235.     b.use :placeholder
  236.  
  237.     b.wrapper tag: 'div', class: 'col-sm-offset-3 col-sm-9' do |wr|
  238.       wr.wrapper tag: 'div', class: 'checkbox' do |ba|
  239.         ba.use :label_input, class: 'col-sm-9'
  240.       end
  241.  
  242.       wr.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  243.       wr.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  244.     end
  245.   end
  246.  
  247.   config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
  248.     b.use :judge
  249.     b.use :html5
  250.     b.use :placeholder
  251.  
  252.     b.use :label, class: 'col-sm-3 control-label'
  253.  
  254.     b.wrapper tag: 'div', class: 'col-sm-9' do |ba|
  255.       ba.use :input
  256.       ba.use :error, wrap_with: { tag: 'span', class: 'help-block' }
  257.       ba.use :hint,  wrap_with: { tag: 'p', class: 'help-block' }
  258.     end
  259.   end
  260.  
  261.  
  262.   ######### Additional bootstrap stuff found somewhere #########
  263.  
  264.   config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
  265.     b.use :judge
  266.     b.use :html5
  267.     b.use :placeholder
  268.     b.use :label
  269.     b.wrapper :tag => 'div', :class => 'controls' do |input|
  270.       input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
  271.         prepend.use :input
  272.       end
  273.       input.use :hint,  :wrap_with => { :tag => 'span', :class => 'help-block' }
  274.       input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
  275.     end
  276.   end
  277.  
  278.   config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
  279.     b.use :judge
  280.     b.use :html5
  281.     b.use :placeholder
  282.     b.use :label
  283.     b.wrapper :tag => 'div', :class => 'controls' do |input|
  284.       input.wrapper :tag => 'div', :class => 'input-append' do |append|
  285.         append.use :input
  286.       end
  287.       input.use :hint,  :wrap_with => { :tag => 'span', :class => 'help-block' }
  288.       input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
  289.     end
  290.   end
  291. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement