diff options
| -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 |
