Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Default Classes For Submit Button In Simple Form

I'm using Simple Form with Rails 3.2. I'm currently adding the same classes to the submit button of each form within my app. There are a lot of forms so this isn't very DRY.

<%= f.button :submit, class: "form-submit" %>

Is there a way to configure Simple Form to use a default class for all submit buttons?

like image 243
Undistraction Avatar asked Sep 24 '13 09:09

Undistraction


People also ask

What is the default for form submission?

method property represents the HTTP method used to submit the <form> . Unless explicitly specified, the default method is 'get'.

How do I customize a submit button?

The simplest way to do this is by using the WordPress CSS Editor. To open this, go to Appearance » Customize and select Additional CSS. Once you've opened the Additional CSS section, you can paste in your new CSS, click the Save & Publish button, and you're all set!

In which of the following ways can a submit button be created?

It is also created using HTML <input> tag but type attribute is set to button. You can try to run the following code to use submit button to submit and reset a form. Under the action, attribute add the file, where you want to reach after clicking Submit button.


1 Answers

Actually it is possible to add default class to button in simple form. In config/initializers/simple_form.rb:

SimpleForm.setup do |config|
  # Default class for buttons
  config.button_class = 'btn form-submit'
end

Tested in Simple Form 3.0.1 Remember to restart server after making changes to files in initializers directory.

like image 100
Gee-Bee Avatar answered Sep 25 '22 05:09

Gee-Bee