Module: SimpleForm::Bootstrap::FormBuilders::Button
- Defined in:
- lib/simple_form/bootstrap/form_builders/button.rb
Constant Summary collapse
- BUTTON_CLASSES =
['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning', 'btn-danger', 'btn-link'].freeze
Instance Method Summary collapse
-
#button(type, *args, &proc) ⇒ Object
Adds the btn-default class selectively to buttons which do not have an explicit button type.
-
#submit_button(*args, &block) ⇒ Object
Creates a submit button.
Instance Method Details
#button(type, *args, &proc) ⇒ Object
Adds the btn-default class selectively to buttons which do not have an explicit button type.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/simple_form/bootstrap/form_builders/button.rb', line 6 def (type, *args, &proc) = args..dup [:class] = [*[:class]] # Add the specified class type. if [:class].select { |cls| BUTTON_CLASSES.include?(cls) }.empty? if type.to_s == :submit.to_s.freeze [:class] << 'btn-primary' else [:class] << 'btn-default' end end args << super(type, *args, &proc) end |
#submit_button(*args, &block) ⇒ Object
Creates a submit button.
This augments the original button implementation to generate a button element with a submit action when a block is given. Otherwise, it falls back to the original submit helper.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simple_form/bootstrap/form_builders/button.rb', line 28 def (*args, &block) if block_given? = args..dup [:type] = :submit [:name] ||= 'commit' args << (, &block) else submit(*args) end end |