diff --git a/app/assets/javascripts/registrar-manifest.coffee b/app/assets/javascripts/registrar-manifest.coffee index 29b950fb4..86b7b4060 100644 --- a/app/assets/javascripts/registrar-manifest.coffee +++ b/app/assets/javascripts/registrar-manifest.coffee @@ -1,12 +1,9 @@ #= require jquery #= require jquery_ujs -#= require jquery.validate -#= require jquery.validate.additional-methods #= require turbolinks #= require bootstrap-sprockets #= require typeahead.bundle.min #= require jquery.nested_attributes -#= require shared/jquery.validate.bootstrap #= require jquery-ui/datepicker #= require select2 diff --git a/app/assets/javascripts/registrar/application.coffee b/app/assets/javascripts/registrar/application.coffee index a1a2084fe..f1b92f0f1 100644 --- a/app/assets/javascripts/registrar/application.coffee +++ b/app/assets/javascripts/registrar/application.coffee @@ -1,8 +1,4 @@ $(document).on 'page:change', -> - # client side validate all forms - $('form').each -> - $(this).validate() - $('.js-contact-form').on 'restoreDefault', (e) -> form = $(e.target) form.find('.js-ident-tip').hide() diff --git a/app/assets/javascripts/shared/jquery.validate.bootstrap.coffee b/app/assets/javascripts/shared/jquery.validate.bootstrap.coffee index 698eb9706..41b63748c 100644 --- a/app/assets/javascripts/shared/jquery.validate.bootstrap.coffee +++ b/app/assets/javascripts/shared/jquery.validate.bootstrap.coffee @@ -17,7 +17,3 @@ $.validator.setDefaults else error.insertAfter element return - -jQuery.validator.addMethod 'lax_email', ((value, element) -> - @optional(element) or (value.match(new RegExp("@", "g")) || []).length == 1 -), 'Please enter a valid email address.' diff --git a/app/views/admin/admin_users/_form.haml b/app/views/admin/admin_users/_form.haml index 0904ea99f..512cddde8 100644 --- a/app/views/admin/admin_users/_form.haml +++ b/app/views/admin/admin_users/_form.haml @@ -38,7 +38,7 @@ .col-md-4.control-label = f.label :email .col-md-8 - = f.text_field(:email, class: 'form-control', lax_email: true) + = f.email_field :email, class: 'form-control' .form-group .col-md-4.control-label = f.label :country_code, t(:country) diff --git a/app/views/admin/mail_templates/_form.haml b/app/views/admin/mail_templates/_form.haml index 6e9d828c5..739cce665 100644 --- a/app/views/admin/mail_templates/_form.haml +++ b/app/views/admin/mail_templates/_form.haml @@ -24,17 +24,17 @@ .col-md-4.control-label = f.label :from .col-md-7 - = f.text_field(:from, class: 'form-control', lax_email: true) + = f.email_field :from, class: 'form-control' .form-group .col-md-4.control-label = f.label :cc .col-md-7 - = f.text_field(:cc, class: 'form-control', lax_email: true) + = f.email_field :cc, class: 'form-control' .form-group .col-md-4.control-label = f.label :bcc .col-md-7 - = f.text_field(:bcc, class: 'form-control', lax_email: true) + = f.email_field :bcc, class: 'form-control' .form-group .col-md-12 = f.label :body, t(:html_body) diff --git a/app/views/admin/registrars/_form.haml b/app/views/admin/registrars/_form.haml index d62a375f8..abf440921 100644 --- a/app/views/admin/registrars/_form.haml +++ b/app/views/admin/registrars/_form.haml @@ -36,12 +36,12 @@ .col-md-4.control-label = f.label :email .col-md-7 - = f.text_field(:email, class: 'form-control', lax_email: true) + = f.email_field :email, class: 'form-control' .form-group .col-md-4.control-label = f.label :billing_email .col-md-7 - = f.text_field(:billing_email, class: 'form-control', lax_email: true) + = f.email_field :billing_email, class: 'form-control' .row .col-md-8 diff --git a/app/views/registrar/contacts/form/_general.haml b/app/views/registrar/contacts/form/_general.haml index a6ecbb500..b8ff90965 100644 --- a/app/views/registrar/contacts/form/_general.haml +++ b/app/views/registrar/contacts/form/_general.haml @@ -61,7 +61,7 @@ .col-md-3.control-label = f.label :email, t(:email) + '*' .col-md-7 - = f.text_field :email, class: 'form-control', required: true, lax_email: true + = f.email_field :email, class: 'form-control', required: true .form-group .col-md-3.control-label diff --git a/spec/requests/admin/registrars/create_spec.rb b/spec/requests/admin/registrars/create_spec.rb index e144b19f8..e66fb0765 100644 --- a/spec/requests/admin/registrars/create_spec.rb +++ b/spec/requests/admin/registrars/create_spec.rb @@ -17,6 +17,16 @@ RSpec.describe 'admin registrar create' do expect(registrar.website).to eq('test') end + it 'saves email' do + post admin_registrars_path, { registrar: attributes_for(:registrar, email: 'test@test.com') } + expect(registrar.email).to eq('test@test.com') + end + + it 'saves billing email' do + post admin_registrars_path, { registrar: attributes_for(:registrar, billing_email: 'test@test.com') } + expect(registrar.billing_email).to eq('test@test.com') + end + it 'redirects to :show' do post admin_registrars_path, { registrar: attributes_for(:registrar) } expect(response).to redirect_to admin_registrar_path(registrar) diff --git a/spec/requests/admin/registrars/update_spec.rb b/spec/requests/admin/registrars/update_spec.rb index fc99bccd0..7bffb99d0 100644 --- a/spec/requests/admin/registrars/update_spec.rb +++ b/spec/requests/admin/registrars/update_spec.rb @@ -14,6 +14,24 @@ RSpec.describe 'admin registrar update' do expect(registrar.website).to eq('new-website') end + it 'updates email' do + registrar = create(:registrar, email: 'test@test.com') + + patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, email: 'new-test@test.com') + registrar.reload + + expect(registrar.email).to eq('new-test@test.com') + end + + it 'updates billing email' do + registrar = create(:registrar, billing_email: 'test@test.com') + + patch admin_registrar_path(registrar), registrar: attributes_for(:registrar, billing_email: 'new-test@test.com') + registrar.reload + + expect(registrar.billing_email).to eq('new-test@test.com') + end + it 'redirects to :show' do registrar = create(:registrar)