diff options
| author | teddywing | 2018-01-10 15:07:18 +0100 |
|---|---|---|
| committer | GitHub | 2018-01-10 15:07:18 +0100 |
| commit | 26b4c1aa0ba40b6a02de529024f1bb213db072df (patch) | |
| tree | 56859d023612b98325f41d7bb8f8174ee226ae8d | |
| parent | 8acb6e53b8b49d210bbab3d8b16fdbb7409d5954 (diff) | |
| parent | db40a5f1eada6aa4f000c0ffbe6c93e3aa18fe1d (diff) | |
| download | chouette-core-26b4c1aa0ba40b6a02de529024f1bb213db072df.tar.bz2 | |
Merge pull request #223 from af83/5525-prevent-double-submission
5525 Add a `disable-with` attr on all submit buttons
| -rw-r--r-- | config/initializers/simple_form/safe_submit.rb | 12 | ||||
| -rw-r--r-- | config/locales/actions.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/actions.fr.yml | 1 | ||||
| -rw-r--r-- | spec/features/safe_submit_spec.rb | 9 |
4 files changed, 23 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..64b9f1e6e --- /dev/null +++ b/config/initializers/simple_form/safe_submit.rb @@ -0,0 +1,12 @@ +::SimpleForm::FormBuilder.class_eval do + def button_with_safe_submit(type, *args, &block) + options = args.extract_options!.dup + if type == :submit + options[:data] ||= {} + options[:data][:disable_with] ||= I18n.t('actions.wait_for_submission') + end + args << options + button_without_safe_submit type, *args, &block + end + alias_method_chain :button, :safe_submit +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/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 |
