Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default disable_with for simple_form submit

I want to change the default behavior of my submit button in simple_form so that I needn't explicitly specify :disable_with => true for all my forms. How can I make this particular change in the simple_form.rb?

like image 893
Appster Avatar asked Jul 05 '12 08:07

Appster


1 Answers

This is a little different in newer versions of Rails, as setting the property disable_with is deprecated. I wrote an article on this: http://www.railsonmaui.com/blog/2014/02/23/simple-form-and-disable-processing-by-default/

Here's the new code:

SimpleForm::FormBuilder.class_eval do
  def submit_with_override(field, options = {})
    data_disable_with = { disable_with: 'Processing...' }
    options[:data] = data_disable_with.merge(options[:data] || {})
    submit_without_override(field, options)
  end
  alias_method_chain :submit, :override
end

And thanks to @Appster for the idea!

like image 94
justingordon Avatar answered Sep 17 '22 23:09

justingordon