diff options
| author | Zog | 2018-01-10 12:30:21 +0100 |
|---|---|---|
| committer | Zog | 2018-01-10 12:30:21 +0100 |
| commit | 9becd65c404bf84b9f7b18b91bc9e20b194c1294 (patch) | |
| tree | 63dde1a71b74cc5ab8219f1aac10481c92332768 | |
| parent | 2fa6e52c311a0ca63d6bb6339bb056ee0dad5b8c (diff) | |
| download | chouette-core-9becd65c404bf84b9f7b18b91bc9e20b194c1294.tar.bz2 | |
Refs #5525 @1h; Add a `diable-with` attr on all submit buttons
| -rw-r--r-- | config/initializers/simple_form/safe_submit.rb | 7 | ||||
| -rw-r--r-- | config/locales/actions.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/actions.fr.yml | 1 | ||||
| -rw-r--r-- | lib/af83/simple_form/safe_submit.rb | 24 | ||||
| -rw-r--r-- | spec/features/safe_submit_spec.rb | 9 |
5 files changed, 42 insertions, 0 deletions
diff --git a/config/initializers/simple_form/safe_submit.rb b/config/initializers/simple_form/safe_submit.rb new file mode 100644 index 000000000..8d10929eb --- /dev/null +++ b/config/initializers/simple_form/safe_submit.rb @@ -0,0 +1,7 @@ +AF83::SimpleForm::SafeSubmit.decorate_simple_form + +if Rails.env.development? + ActionDispatch::Reloader.to_prepare do + AF83::SimpleForm::SafeSubmit.decorate_simple_form + end +end diff --git a/config/locales/actions.en.yml b/config/locales/actions.en.yml index 08d505393..278915526 100644 --- a/config/locales/actions.en.yml +++ b/config/locales/actions.en.yml @@ -25,6 +25,7 @@ en: erase: 'Erase' create_api_key: "Create an API key" select: Select + wait_for_submission: "Please wait..." or: "or" cancel: "Cancel" back: "Go Back" diff --git a/config/locales/actions.fr.yml b/config/locales/actions.fr.yml index 4690c995a..92e16f21e 100644 --- a/config/locales/actions.fr.yml +++ b/config/locales/actions.fr.yml @@ -25,6 +25,7 @@ fr: erase: 'Effacer' create_api_key: "Créer une clé d'API" select: Sélectionner + wait_for_submission: "Validation..." or: "ou" cancel: "Annuler" back: "Retour" diff --git a/lib/af83/simple_form/safe_submit.rb b/lib/af83/simple_form/safe_submit.rb new file mode 100644 index 000000000..d4d84f90d --- /dev/null +++ b/lib/af83/simple_form/safe_submit.rb @@ -0,0 +1,24 @@ +module AF83 + module SimpleForm + module SafeSubmit + def self.decorate_simple_form + ::SimpleForm::FormBuilder.class_eval do + def button(type, *args, &block) + options = args.extract_options!.dup + options[:class] = [::SimpleForm.button_class, options[:class]].compact + if type == :submit + options[:data] ||= {} + options[:data][:disable_with] ||= I18n.t('actions.wait_for_submission') + end + args << options + if respond_to?(:"#{type}_button") + send(:"#{type}_button", *args, &block) + else + send(type, *args, &block) + end + end + end + end + end + end +end diff --git a/spec/features/safe_submit_spec.rb b/spec/features/safe_submit_spec.rb new file mode 100644 index 000000000..9968d4310 --- /dev/null +++ b/spec/features/safe_submit_spec.rb @@ -0,0 +1,9 @@ +RSpec.describe 'SafeSubmit', type: :feature do + login_user + + let( :path ){ new_api_key_path() } + it 'view shows the corresponding buttons' do + visit path + expect(page).to have_css('input[type=submit][data-disable-with]') + end +end |
