You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
6.5 KiB

  1. # Use this setup block to configure all options available in SimpleForm.
  2. SimpleForm.setup do |config|
  3. # Wrappers are used by the form builder to generate a
  4. # complete input. You can remove any component from the
  5. # wrapper, change the order or even add your own to the
  6. # stack. The options given below are used to wrap the
  7. # whole input.
  8. config.wrappers :default, class: :input,
  9. hint_class: :field_with_hint, error_class: :field_with_errors do |b|
  10. ## Extensions enabled by default
  11. # Any of these extensions can be disabled for a
  12. # given input by passing: `f.input EXTENSION_NAME => false`.
  13. # You can make any of these extensions optional by
  14. # renaming `b.use` to `b.optional`.
  15. # Determines whether to use HTML5 (:email, :url, ...)
  16. # and required attributes
  17. b.use :html5
  18. # Calculates placeholders automatically from I18n
  19. # You can also pass a string as f.input placeholder: "Placeholder"
  20. b.use :placeholder
  21. ## Optional extensions
  22. # They are disabled unless you pass `f.input EXTENSION_NAME => true`
  23. # to the input. If so, they will retrieve the values from the model
  24. # if any exists. If you want to enable any of those
  25. # extensions by default, you can change `b.optional` to `b.use`.
  26. # Calculates maxlength from length validations for string inputs
  27. b.optional :maxlength
  28. # Calculates pattern from format validations for string inputs
  29. b.optional :pattern
  30. # Calculates min and max from length validations for numeric inputs
  31. b.optional :min_max
  32. # Calculates readonly automatically from readonly attributes
  33. b.optional :readonly
  34. ## Inputs
  35. b.use :input
  36. b.use :hint, wrap_with: { tag: :span, class: :hint }
  37. b.use :error, wrap_with: { tag: :span, class: :error }
  38. ## full_messages_for
  39. # If you want to display the full error message for the attribute, you can
  40. # use the component :full_error, like:
  41. #
  42. # b.use :full_error, wrap_with: { tag: :span, class: :error }
  43. end
  44. config.wrappers :with_label, class: :input,
  45. hint_class: :field_with_hint, error_class: :field_with_errors do |b|
  46. b.use :html5
  47. b.use :hint, wrap_with: { tag: :span, class: :hint }
  48. b.use :error, wrap_with: { tag: :span, class: :error }
  49. b.use :label_input
  50. end
  51. # The default wrapper to be used by the FormBuilder.
  52. config.default_wrapper = :default
  53. # Define the way to render check boxes / radio buttons with labels.
  54. # Defaults to :nested for bootstrap config.
  55. # inline: input + label
  56. # nested: label > input
  57. config.boolean_style = :nested
  58. # Default class for buttons
  59. config.button_class = 'btn'
  60. # Method used to tidy up errors. Specify any Rails Array method.
  61. # :first lists the first message for each field.
  62. # Use :to_sentence to list all errors for each field.
  63. # config.error_method = :first
  64. # Default tag used for error notification helper.
  65. config.error_notification_tag = :div
  66. # CSS class to add for error notification helper.
  67. config.error_notification_class = 'error_notification'
  68. # ID to add for error notification helper.
  69. # config.error_notification_id = nil
  70. # Series of attempts to detect a default label method for collection.
  71. # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
  72. # Series of attempts to detect a default value method for collection.
  73. # config.collection_value_methods = [ :id, :to_s ]
  74. # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
  75. # config.collection_wrapper_tag = nil
  76. # You can define the class to use on all collection wrappers. Defaulting to none.
  77. # config.collection_wrapper_class = nil
  78. # You can wrap each item in a collection of radio/check boxes with a tag,
  79. # defaulting to :span.
  80. # config.item_wrapper_tag = :span
  81. # You can define a class to use in all item wrappers. Defaulting to none.
  82. # config.item_wrapper_class = nil
  83. # How the label text should be generated altogether with the required text.
  84. # config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
  85. # You can define the class to use on all labels. Default is nil.
  86. # config.label_class = nil
  87. # You can define the default class to be used on forms. Can be overriden
  88. # with `html: { :class }`. Defaulting to none.
  89. # config.default_form_class = nil
  90. # You can define which elements should obtain additional classes
  91. # config.generate_additional_classes_for = [:wrapper, :label, :input]
  92. # Whether attributes are required by default (or not). Default is true.
  93. # config.required_by_default = true
  94. # Tell browsers whether to use the native HTML5 validations (novalidate form option).
  95. # These validations are enabled in SimpleForm's internal config but disabled by default
  96. # in this configuration, which is recommended due to some quirks from different browsers.
  97. # To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
  98. # change this configuration to true.
  99. config.browser_validations = false
  100. # Collection of methods to detect if a file type was given.
  101. # config.file_methods = [ :mounted_as, :file?, :public_filename ]
  102. # Custom mappings for input types. This should be a hash containing a regexp
  103. # to match as key, and the input type that will be used when the field name
  104. # matches the regexp as value.
  105. # config.input_mappings = { /count/ => :integer }
  106. # Custom wrappers for input types. This should be a hash containing an input
  107. # type as key and the wrapper that will be used for all inputs with specified type.
  108. # config.wrapper_mappings = { string: :prepend }
  109. # Namespaces where SimpleForm should look for custom input classes that
  110. # override default inputs.
  111. # config.custom_inputs_namespaces << "CustomInputs"
  112. # Default priority for time_zone inputs.
  113. # config.time_zone_priority = nil
  114. # Default priority for country inputs.
  115. # config.country_priority = nil
  116. # When false, do not use translations for labels.
  117. # config.translate_labels = true
  118. # Automatically discover new inputs in Rails' autoload path.
  119. # config.inputs_discovery = true
  120. # Cache SimpleForm inputs discovery
  121. # config.cache_discovery = !Rails.env.development?
  122. # Default class for inputs
  123. # config.input_class = nil
  124. # Define the default class of the input wrapper of the boolean input.
  125. config.boolean_label_class = 'checkbox'
  126. # Defines if the default input wrapper class should be included in radio
  127. # collection wrappers.
  128. # config.include_default_input_wrapper_class = true
  129. # Defines which i18n scope will be used in Simple Form.
  130. # config.i18n_scope = 'simple_form'
  131. end