Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Commit button disable_with option #466

Closed
wants to merge 1 commit into from

3 participants

@dbackeus

Rails supports :disable_with => "Text to display on button while submitting..." as an option to the form.submit and submit_tag methods.

This implementation is the same as is used in Rails 3 and hooks in to the rails.js stuff just fine.

Probably not compatible with old school non unobtrusive Rails 2 stuff though.

@justinfrench

I'm going to sit on this until we drop 2.x support (which is actually really soon).

@sobrinho
Collaborator

Closing.

Currently this works on input_html:

f.commit_button :button_html => { :disable_with => 'Aguarde...' }
@dbackeus

Ok that's cool. A statement about it in the docs would help though as this is quite obscure.

@justinfrench

@dbackeus :button_html is briefly mentioned in the README and well documented in the refactor I'm doing (see Formtastic::Helpers::ButtonsHelper and #commit_button in master). If you think anything further will be needed, would love a patch or even specific suggestions in this thread will do. Documentation is a big deal to me in v2.

@dbackeus

Well, optimally I would still implement the :disable_with option and just provide an example with that in the README. Keeping in mind the "principle of least surprise" design we're used to in Ruby. If it works in Rails I hope it to work the same way in Formtastic.

Especially given that going the route of :button_html => { :data-disable-with => "xxx" } requires knowledge about the implementation details of what Rails actually does when using the disable_with option.

But if you keep it that way adding that option to your existing commit_button example in the README would probably suffice. Allowing people to find it through cmd+f with "disable" in their browser / text-editor (which is how I usually go about finding this kind of stuff).

@justinfrench

Re-opening until this can be made clear.

@justinfrench justinfrench reopened this
@justinfrench
Owner

I've added documentation as suggested. We're toying with the idea of moving all the input_html / button_html options up to the same namespace as the options, which would ultimately result in the same API as what your patch was aiming for.

@dbackeus

I believe the example in the documentation is incorrect. The class should be data-disable-with and not disable_with.

Thus also remaining incompatible with the Rails api even if you flatten out the namespacing (which doesn't sound like a bad idea to me btw).

@sodabrew sodabrew referenced this pull request in mjbellantoni/formtastic-bootstrap
Closed

Add data-disable-with attributes if found in i18n. #75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 1 deletion.
  1. +1 −0  lib/formtastic.rb
  2. +23 −1 spec/commit_button_spec.rb
View
1  lib/formtastic.rb
@@ -359,6 +359,7 @@ def commit_button(*args)
button_html = options.delete(:button_html) || {}
button_html.merge!(:class => [button_html[:class], key].compact.join(' '))
+ button_html.merge!('data-disable-with' => options.delete(:disable_with)) if options[:disable_with]
wrapper_html_class = ['commit'] # TODO: Add class reflecting on form action.
wrapper_html = options.delete(:wrapper_html) || {}
View
24 spec/commit_button_spec.rb
@@ -478,7 +478,29 @@ def self.human_name
end
-
+ describe ':disable_with option' do
+
+ describe 'when provided' do
+ it 'should add data-disable-with attribute to the button' do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.commit_button('text', :disable_with => "Submitting"))
+ end
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form li input[data-disable-with=Submitting]")
+ end
+ end
+
+ describe 'when not provided' do
+ it 'should not add the data-disable-with attribute to the button' do
+ form = semantic_form_for(@new_post) do |builder|
+ concat(builder.commit_button('text'))
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should_not have_tag("li.commit input[data-disable-with]")
+ end
+ end
+ end
+
+ end
end
Something went wrong with that request. Please try again.