From b447d83497ef66fe60e004317b94bffc053d1949 Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Wed, 6 May 2015 11:50:30 +0100 Subject: [PATCH 1/9] extra validation on errors --- .../javascripts/income_calculator.coffee | 8 +++-- app/views/calculator/income.html.slim | 32 +++++++++++-------- app/views/dwp_checks/new.html.slim | 5 +++ app/views/users/invitations/new.html.slim | 4 +-- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/income_calculator.coffee b/app/assets/javascripts/income_calculator.coffee index 0424e3866..984af8e46 100644 --- a/app/assets/javascripts/income_calculator.coffee +++ b/app/assets/javascripts/income_calculator.coffee @@ -62,13 +62,17 @@ sendToDatabase = (remit, pay) -> checkValidation = -> $('input[data-check]').each -> test = $(this) - error = $('small.error[data-check-error=' + test.data('check') + ']') + error = $('label.error[data-check-error=' + test.data('check') + ']') + parent = error.parents('.form-group') if test.val().length == 0 or test.is(':radio') and $('input[name=' + test.attr('name') + ']:checked').val() == undefined error.removeClass 'hide' + parent.addClass 'field_with_errors' else error.addClass 'hide' + parent.removeClass 'field_with_errors' + return - $('small.error:visible').length == 0 + $('label.error:visible').length == 0 setupPage = -> $('.panel.callout').hide() diff --git a/app/views/calculator/income.html.slim b/app/views/calculator/income.html.slim index 55762afcc..70da8bd38 100644 --- a/app/views/calculator/income.html.slim +++ b/app/views/calculator/income.html.slim @@ -12,18 +12,24 @@ h2 Income check label.inline for='fee' £ .small-10.medium-10.large-9.columns style="padding:0px;" input data-check='fee' id="fee" name="fee" type="number" - small.error data-check-error='fee' Please enter a fee value + label.error data-check-error='fee' Please enter a fee value .row - .small-12.medium-3.large-3.columns - .row - .small-12.columns - label for='couple-no' - input id='couple-no' name="couple" type="radio" value='false' - | Single - label for='couple-yes' - input data-check='couple' id='couple-yes' name="couple" type="radio" value='true' - | Part of a couple - small.error data-check-error='couple' Please select a marital status + .small-12.columns + .form-group + #couple + .row + .columns.small-12 + label.error data-check-error='couple' Please select a marital status + .row + .columns.small-4 + label Marital status + label for='couple-no' + input id='couple-no' name="couple" type="radio" value='false' + | Single + label for='couple-yes' + input data-check='couple' id='couple-yes' name="couple" type="radio" value='true' + | Part of a couple + .row .small-12.medium-6.large-5.columns @@ -31,7 +37,7 @@ h2 Income check .row .columns.small-3 input data-check='children' id='children' type="number" min=0 - small.error data-check-error='children' Please select a number of children + label.error data-check-error='children' Please select a number of children .row .small-12.medium-3.large-3.columns @@ -42,7 +48,7 @@ h2 Income check label.inline for='income' £ .small-10.medium-10.large-9.columns input data-check='income' name="income" id="income" type="number" - small.error data-check-error='income' Please enter an income + label.error data-check-error='income' Please enter an income .row .small-12.medium-8.large-5.columns diff --git a/app/views/dwp_checks/new.html.slim b/app/views/dwp_checks/new.html.slim index 2853f89de..3c3652f75 100644 --- a/app/views/dwp_checks/new.html.slim +++ b/app/views/dwp_checks/new.html.slim @@ -28,6 +28,11 @@ h2 Check benefits status .small-12.medium-8.large-5.columns .form-group = f.label :date_to_check +<<<<<<< Updated upstream +======= + = t 'activerecord.attributes.dwp_check.date_to_check' + span.hint.block = t('activerecord.attributes.dwp_check.date_to_check_hint') +>>>>>>> Stashed changes = f.text_field :date_to_check, { class: 'form-control' } .row .small-12.medium-8.large-5.columns diff --git a/app/views/users/invitations/new.html.slim b/app/views/users/invitations/new.html.slim index afcc94e23..9944bfde2 100644 --- a/app/views/users/invitations/new.html.slim +++ b/app/views/users/invitations/new.html.slim @@ -3,11 +3,9 @@ h2 = form_for resource, as: resource_name, url: user_invitation_path, html: {:method => :post} do |f| = devise_error_messages! - resource.class.invite_key_fields.each do |field| - p + .form-group = f.label field - br = f.text_field field - p .form-group = f.label :name = f.text_field :name, { class: 'form-control' } From 68c30349e6378cd80a856b33f2e515f472d1335a Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Wed, 6 May 2015 16:06:39 +0100 Subject: [PATCH 2/9] Changes for users moved to translation file * views and tests updated --- app/assets/stylesheets/errors.scss | 14 +++++++ app/models/user.rb | 2 +- app/views/users/invitations/new.html.slim | 47 ++++++++++++++++------- config/locales/en.yml | 20 +++++++++- spec/models/user_spec.rb | 12 ++++++ 5 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 app/assets/stylesheets/errors.scss diff --git a/app/assets/stylesheets/errors.scss b/app/assets/stylesheets/errors.scss new file mode 100644 index 000000000..c96d0a89b --- /dev/null +++ b/app/assets/stylesheets/errors.scss @@ -0,0 +1,14 @@ +@import 'colours'; + +div.field_with_errors input { + border-color: $error-colour; +} + +div.form-group div.field_with_errors { + border-left: 2px solid $error-colour; + padding-left: 10px; +} + +div.field_with_errors > label.error { + color: $error-colour; +} diff --git a/app/models/user.rb b/app/models/user.rb index 2e5b91ebe..f192dc4cf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,8 +13,8 @@ class User < ActiveRecord::Base scope :sorted_by_email, -> { all.order(:email) } email_regex = /\A([^@\s]+)@(hmcts\.gsi|digital\.justice)\.gov\.uk\z/i - validates :email, format: { with: email_regex, on: :create } validates :role, :name, presence: true + validates :email, format: { with: email_regex, on: :create, allow_nil: true } validates :role, inclusion: { in: ROLES, message: "%{value} is not a valid role", diff --git a/app/views/users/invitations/new.html.slim b/app/views/users/invitations/new.html.slim index 9944bfde2..7b0eab34b 100644 --- a/app/views/users/invitations/new.html.slim +++ b/app/views/users/invitations/new.html.slim @@ -1,19 +1,40 @@ h2 = t "devise.invitations.new.header" = form_for resource, as: resource_name, url: user_invitation_path, html: {:method => :post} do |f| - = devise_error_messages! - resource.class.invite_key_fields.each do |field| - .form-group - = f.label field - = f.text_field field - .form-group - = f.label :name - = f.text_field :name, { class: 'form-control' } - .form-group - = f.label(:roles, 'Role') - = f.collection_select :role, User::ROLES, :to_s, :humanize - .form-group - = f.label(:office_id, 'Office') - = f.collection_select :office_id, Office.all, :id, :name + .row + .small-12.columns + .form-group + .row + .columns.small-12 + = f.label field, resource.errors[field].join(', ').html_safe, class: 'error' if resource.errors[field].present? + .row + .columns.small-12.medium-8.large-5 + = f.label field + = f.text_field field + .row + .small-12.columns + .form-group + .row + .columns.small-12 + = f.label :name, resource.errors[:name].join(', ').html_safe, class: 'error' if resource.errors[:name].present? + .row + .columns.small-12.medium-8.large-5 + = f.label :name + = f.text_field :name, { class: 'form-control' } + .row + .small-12.columns + .form-group + .row + .columns.small-12.medium-8.large-5 + = f.label(:roles, 'Role') + = f.collection_select :role, User::ROLES, :to_s, :humanize + .row + .small-12.columns + .form-group + .row + .columns.small-12.medium-8.large-5 + = f.label(:office_id, 'Office') + = f.collection_select :office_id, Office.all, :id, :name p = f.submit t("devise.invitations.new.submit_button"), class: 'button btn tiny' diff --git a/config/locales/en.yml b/config/locales/en.yml index c61e5fecc..2fcb0c2ce 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,7 +20,6 @@ # available at http://guides.rubyonrails.org/i18n.html. en: - hello: "Hello world" descriptors: r2_calculator: 'Income check' feedback: 'Feedback' @@ -30,6 +29,25 @@ en: rating_3: 'I needed other kind of help' rating_4: 'Other' activerecord: + errors: + models: + user: + attributes: + email: + blank: 'You must enter an @hmcts.gsi.gov.uk email address' + invalid: "You’re not able to create an account with this email address. Only 'name@hmcts.gsi.gov.uk' emails can be used. For more help, contact us" + name: + blank: You must enter a name for the user + dwp_check: + attributes: + last_name: + blank: 'Enter the applicant’s last name' + dob: + blank: 'Enter the applicant’s date of birth' + invalid: 'Enter the date as ‘day, month, year DD/MM/YY' + ni_number: + blank: 'Enter the applicant’s National Insurance number' + invalid: 'Enter 2 letters, 6 numbers and 1 letter for the National Insurance number' attributes: feedback: experience: 'What is your experience of using the service so far?' diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a5c947d7e..efc95c996 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -39,6 +39,18 @@ it 'will not accept non white listed emails' do user.email = 'valid.email.that.rocks@gmail.com' expect(user).to be_invalid + context 'non white listed emails' do + let(:invalid_email) { 'email.that.rocks@gmail.com' } + before(:each) { user.email = invalid_email } + + it 'will not accept non white listed emails' do + expect(user).to be_invalid + end + + it 'has an informative error message for non white listed emails' do + user.valid? + expect(user.errors.messages[:email].first).to match I18n.t('activerecord.errors.models.user.attributes.email.invalid') + end end end end From 65e1f4e9d089c760d8a8594fcb3404a79a94e902 Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Wed, 6 May 2015 16:12:49 +0100 Subject: [PATCH 3/9] fixed tests --- app/views/dwp_checks/new.html.slim | 4 ---- spec/features/perform_an_income_check_spec.rb | 4 ++-- spec/models/user_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/views/dwp_checks/new.html.slim b/app/views/dwp_checks/new.html.slim index 3c3652f75..ea9d2c8b8 100644 --- a/app/views/dwp_checks/new.html.slim +++ b/app/views/dwp_checks/new.html.slim @@ -28,11 +28,7 @@ h2 Check benefits status .small-12.medium-8.large-5.columns .form-group = f.label :date_to_check -<<<<<<< Updated upstream -======= = t 'activerecord.attributes.dwp_check.date_to_check' - span.hint.block = t('activerecord.attributes.dwp_check.date_to_check_hint') ->>>>>>> Stashed changes = f.text_field :date_to_check, { class: 'form-control' } .row .small-12.medium-8.large-5.columns diff --git a/spec/features/perform_an_income_check_spec.rb b/spec/features/perform_an_income_check_spec.rb index 7d0c19d9e..2341413a3 100644 --- a/spec/features/perform_an_income_check_spec.rb +++ b/spec/features/perform_an_income_check_spec.rb @@ -32,7 +32,7 @@ end scenario 'shows a successful result', js: true do expect(page).to have_xpath('//div[@class="panel callout"]', visible: true) - expect(page).to have_xpath('//small[@class="error hide"]', count: 0) + expect(page).to have_xpath('//label[@class="error hide"]', count: 0) end scenario 'calculates correct values', js: true do expect(page).to have_xpath('//span[@id="fee-remit"]', text: '£200') @@ -46,7 +46,7 @@ click_button 'Check' expect(page).to have_xpath('//div[@class="panel callout"]', visible: false) - expect(page).to have_xpath('//small[@class="error"]', count: 3) + expect(page).to have_xpath('//label[@class="error"]', count: 3) end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index efc95c996..857224344 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -39,6 +39,8 @@ it 'will not accept non white listed emails' do user.email = 'valid.email.that.rocks@gmail.com' expect(user).to be_invalid + end + context 'non white listed emails' do let(:invalid_email) { 'email.that.rocks@gmail.com' } before(:each) { user.email = invalid_email } From 99e5f0559c745d6f7b394d076565cc1dc33c15e1 Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Wed, 6 May 2015 16:17:01 +0100 Subject: [PATCH 4/9] Removed merge duplicated test --- spec/models/user_spec.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c0fda4eb2..f7cde601f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -36,21 +36,6 @@ expect(user).to be_valid end - context 'non white listed emails' do - let(:invalid_email) { 'email.that.rocks@gmail.com' } - before(:each) { user.email = invalid_email } - - it 'will not accept non white listed emails' do - expect(user).to be_invalid - end - - it 'has an informative error message for non white listed emails' do - message = "you’re not able to create an account with this email address. Only 'name@hmcts.gsi.gov.uk' emails can be used. For more help, contact us via #{Settings.mail_tech_support}" - user.valid? - expect(user.errors.messages[:email].first).to match message - end - end - context 'non white listed emails' do let(:invalid_email) { 'email.that.rocks@gmail.com' } before(:each) { user.email = invalid_email } From 58e7ed25cc3b4ba406fa7901266cc7c556e7e5ac Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Wed, 6 May 2015 16:26:00 +0100 Subject: [PATCH 5/9] Dynamic email in user validation * moved message out of validation in translation * called explicitly from model * updated test --- app/models/user.rb | 7 ++++++- config/locales/en.yml | 3 ++- spec/models/user_spec.rb | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index f192dc4cf..5563f2b73 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,7 +14,12 @@ class User < ActiveRecord::Base email_regex = /\A([^@\s]+)@(hmcts\.gsi|digital\.justice)\.gov\.uk\z/i validates :role, :name, presence: true - validates :email, format: { with: email_regex, on: :create, allow_nil: true } + validates :email, format: { + with: email_regex, + on: :create, + allow_nil: true, + message: I18n.t('dictionary.invalid_email', email: Settings.mail_tech_support) + } validates :role, inclusion: { in: ROLES, message: "%{value} is not a valid role", diff --git a/config/locales/en.yml b/config/locales/en.yml index 4d6bd9fe1..52867b753 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,6 +20,8 @@ # available at http://guides.rubyonrails.org/i18n.html. en: + dictionary: + invalid_email: "You’re not able to create an account with this email address. Only 'name@hmcts.gsi.gov.uk' emails can be used. For more help, contact us" descriptors: r2_calculator: 'Income check' feedback: 'Feedback' @@ -35,7 +37,6 @@ en: attributes: email: blank: 'You must enter an @hmcts.gsi.gov.uk email address' - invalid: "You’re not able to create an account with this email address. Only 'name@hmcts.gsi.gov.uk' emails can be used. For more help, contact us" name: blank: You must enter a name for the user dwp_check: diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f7cde601f..73828eaeb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -46,7 +46,7 @@ it 'has an informative error message for non white listed emails' do user.valid? - expect(user.errors.messages[:email].first).to match I18n.t('activerecord.errors.models.user.attributes.email.invalid') + expect(user.errors.messages[:email].first).to match I18n.t('dictionary.invalid_email', email: Settings.mail_tech_support) end end end From 0b5223f258043e0b3321d0c66acc98b6fc7582ca Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Thu, 7 May 2015 09:47:36 +0100 Subject: [PATCH 6/9] Updated user styling * moved to foundation base * updated text and labels inline with copy changes * moved validation and display texts into locale file * updated tests to reflect text changes --- app/views/users/invitations/edit.html.slim | 31 +++++++++++++------- app/views/users/passwords/new.html.slim | 15 +++++++--- app/views/users/sessions/new.html.slim | 2 +- app/views/users/shared/_links.html.slim | 2 +- config/locales/devise_invitable.en.yml | 4 +-- config/locales/en.yml | 12 +++++++- spec/features/user_can_accept_invite_spec.rb | 2 +- 7 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/views/users/invitations/edit.html.slim b/app/views/users/invitations/edit.html.slim index b6bef773e..cfe38bd7a 100644 --- a/app/views/users/invitations/edit.html.slim +++ b/app/views/users/invitations/edit.html.slim @@ -1,15 +1,26 @@ h2 = t 'devise.invitations.edit.header' = form_for resource, as: resource_name, url: invitation_path(resource_name), html: { method: :put } do |f| - = devise_error_messages! = f.hidden_field :invitation_token - p - = f.label :password - br - = f.password_field :password - p - = f.label :password_confirmation - br - = f.password_field :password_confirmation - p + .row + .small-12.columns + .form-group + .row + .columns.small-12 + = f.label :password, resource.errors[:password].join(', ').html_safe, class: 'error' if resource.errors[:password].present? + .row + .columns.small-12.medium-8.large-5 + = f.label :password + = f.text_field :password, { class: 'form-control' } + .row + .small-12.columns + .form-group + .row + .columns.small-12 + = f.label :password_confirmation, resource.errors[:password_confirmation].join(', ').html_safe, class: 'error' if resource.errors[:password_confirmation].present? + .row + .columns.small-12.medium-8.large-5 + = f.label :password_confirmation + = f.text_field :password_confirmation, { class: 'form-control' } + .actions = f.submit t("devise.invitations.edit.submit_button"), class: 'button btn tiny' diff --git a/app/views/users/passwords/new.html.slim b/app/views/users/passwords/new.html.slim index b99373c67..b62318bb8 100644 --- a/app/views/users/passwords/new.html.slim +++ b/app/views/users/passwords/new.html.slim @@ -1,9 +1,16 @@ h2 Forgot your password? +#instructions Enter your email address and click ‘get new password’. You’ll receive an email with a link to create a new password. = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| - = devise_error_messages! - .field - = f.label :email - = f.email_field :email, autofocus: true + .row + .small-12.columns + .form-group + .row + .columns.small-12 + = f.label :email, resource.errors[:email].join(', ').html_safe, class: 'error' if resource.errors[:email].present? + .row + .columns.small-12.medium-8.large-5 + = f.label :email + = f.text_field :email, { class: 'form-control' } .actions = f.submit "Send me reset password instructions", class: 'button btn tiny' = render "devise/shared/links" diff --git a/app/views/users/sessions/new.html.slim b/app/views/users/sessions/new.html.slim index 55a50e96a..83ef991ec 100644 --- a/app/views/users/sessions/new.html.slim +++ b/app/views/users/sessions/new.html.slim @@ -1,4 +1,4 @@ -h2 Log in +h2 Help with fees = form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| .row .small-12.medium-8.large-5.columns diff --git a/app/views/users/shared/_links.html.slim b/app/views/users/shared/_links.html.slim index 9fa8693b5..0eaace0f2 100644 --- a/app/views/users/shared/_links.html.slim +++ b/app/views/users/shared/_links.html.slim @@ -5,7 +5,7 @@ = link_to "Sign up", new_registration_path(resource_name) br - if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' - = link_to "Forgot your password?", new_password_path(resource_name) + = link_to "Forgotten password?", new_password_path(resource_name) br - if devise_mapping.confirmable? && controller_name != 'confirmations' = link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) diff --git a/config/locales/devise_invitable.en.yml b/config/locales/devise_invitable.en.yml index df0c920da..23c33ab54 100644 --- a/config/locales/devise_invitable.en.yml +++ b/config/locales/devise_invitable.en.yml @@ -12,8 +12,8 @@ en: header: "Send invitation" submit_button: "Send an invitation" edit: - header: "Set your password" - submit_button: "Set my password" + header: "Create a new password" + submit_button: "Update password" mailer: invitation_instructions: subject: 'Set up your account to use the benefit checker' diff --git a/config/locales/en.yml b/config/locales/en.yml index 52867b753..dec0c1f67 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -36,9 +36,16 @@ en: user: attributes: email: - blank: 'You must enter an @hmcts.gsi.gov.uk email address' + blank: 'Enter your email address' + invalid: You must enter an @hmcts.gsi.gov.uk email address + not_found: That email is not registered on our system name: blank: You must enter a name for the user + password: + blank: You must enter a password of at least %{count} characters + too_short: The password should be at least %{count} characters + password_confirmation: + confirmation: This must match the password above dwp_check: attributes: last_name: @@ -50,6 +57,9 @@ en: blank: 'Enter the applicant’s National Insurance number' invalid: 'Enter 2 letters, 6 numbers and 1 letter for the National Insurance number' attributes: + user: + password: New password + password_confirmation: Confirm new password feedback: experience: 'What is your experience of using the service so far?' ideas: 'Do you have any ideas for how this service could be improved?' diff --git a/spec/features/user_can_accept_invite_spec.rb b/spec/features/user_can_accept_invite_spec.rb index db9677c87..6c1a69296 100644 --- a/spec/features/user_can_accept_invite_spec.rb +++ b/spec/features/user_can_accept_invite_spec.rb @@ -17,7 +17,7 @@ fill_in 'user_password', with: password fill_in 'user_password_confirmation', with: password - click_button 'Set my password' + click_button I18n.t('devise.invitations.edit.submit_button') expect(page).to have_xpath('//div', text: 'dashboard', count: 2) expect(page).to have_xpath('//div[@class="alert-box notice"]', From a25611fefb15ee7666ddb775730679298e8999fd Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Thu, 7 May 2015 10:38:05 +0100 Subject: [PATCH 7/9] Updated r2 calculator to new style errors --- .../javascripts/income_calculator.coffee | 2 +- app/views/calculator/income.html.slim | 78 +++++++++---------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/app/assets/javascripts/income_calculator.coffee b/app/assets/javascripts/income_calculator.coffee index 984af8e46..98b4b2782 100644 --- a/app/assets/javascripts/income_calculator.coffee +++ b/app/assets/javascripts/income_calculator.coffee @@ -63,7 +63,7 @@ checkValidation = -> $('input[data-check]').each -> test = $(this) error = $('label.error[data-check-error=' + test.data('check') + ']') - parent = error.parents('.form-group') + parent = error.parents('.form-group').children('div') if test.val().length == 0 or test.is(':radio') and $('input[name=' + test.attr('name') + ']:checked').val() == undefined error.removeClass 'hide' parent.addClass 'field_with_errors' diff --git a/app/views/calculator/income.html.slim b/app/views/calculator/income.html.slim index 70da8bd38..f725c3dfa 100644 --- a/app/views/calculator/income.html.slim +++ b/app/views/calculator/income.html.slim @@ -4,51 +4,51 @@ h2 Income check #r2_calculator .row - .small-12.medium-3.large-3.columns - label for='fee' Fee - .row.collapse.prefix-radius - .small-2.medium-2.large-3.columns - span.prefix - label.inline for='fee' £ - .small-10.medium-10.large-9.columns style="padding:0px;" - input data-check='fee' id="fee" name="fee" type="number" - label.error data-check-error='fee' Please enter a fee value + .small-12.medium-3.large-3.columns.form-group + #fee-block + label.error data-check-error='fee' for='fee' Please enter a fee value + label for='fee' Fee + .row.collapse.prefix-radius + .small-2.medium-2.large-3.columns + span.prefix + label.inline for='fee' £ + .small-10.medium-10.large-9.columns style="padding:0px;" + input data-check='fee' id="fee" name="fee" type="number" .row - .small-12.columns - .form-group - #couple - .row - .columns.small-12 - label.error data-check-error='couple' Please select a marital status - .row - .columns.small-4 - label Marital status - label for='couple-no' - input id='couple-no' name="couple" type="radio" value='false' - | Single - label for='couple-yes' - input data-check='couple' id='couple-yes' name="couple" type="radio" value='true' - | Part of a couple + .small-12.columns.form-group + #status-block + label.error data-check-error='couple' Please select a marital status + .row + .columns.small-4 + label Marital status + label for='couple-no' + input data-check='couple' id='couple-no' name="couple" type="radio" value='false' + | Single + label for='couple-yes' + input data-check='couple' id='couple-yes' name="couple" type="radio" value='true' + | Part of a couple .row - .small-12.medium-6.large-5.columns - label for='children' Number of children - .row - .columns.small-3 - input data-check='children' id='children' type="number" min=0 - label.error data-check-error='children' Please select a number of children + .small-12.medium-6.large-5.columns.form-group + #child-block + label.error data-check-error='children' for='children' Please select a number of children + label for='children' Number of children + .row + .columns.small-3 + input data-check='children' id='children' type="number" min=0 .row - .small-12.medium-3.large-3.columns - label for='income' Total monthly income - .row.collapse.prefix-radius - .small-2.medium-2.large-3.columns - span.prefix - label.inline for='income' £ - .small-10.medium-10.large-9.columns - input data-check='income' name="income" id="income" type="number" - label.error data-check-error='income' Please enter an income + .small-12.medium-3.large-3.columns.form-group + #income-block + label.error data-check-error='income' for='income' Please enter an income + label for='income' Total monthly income + .row.collapse.prefix-radius + .small-2.medium-2.large-3.columns + span.prefix + label.inline for='income' £ + .small-10.medium-10.large-9.columns + input data-check='income' name="income" id="income" type="number" .row .small-12.medium-8.large-5.columns From 5982b051365129de944043cdd080fd03e53e729f Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Thu, 7 May 2015 10:38:32 +0100 Subject: [PATCH 8/9] Updated styles * r2 calculator * errors --- app/assets/stylesheets/errors.scss | 2 +- app/assets/stylesheets/r2_calculator.scss | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/errors.scss b/app/assets/stylesheets/errors.scss index c96d0a89b..42ecb7575 100644 --- a/app/assets/stylesheets/errors.scss +++ b/app/assets/stylesheets/errors.scss @@ -9,6 +9,6 @@ div.form-group div.field_with_errors { padding-left: 10px; } -div.field_with_errors > label.error { +div.field_with_errors label.error { color: $error-colour; } diff --git a/app/assets/stylesheets/r2_calculator.scss b/app/assets/stylesheets/r2_calculator.scss index 7550396e4..4fd57538b 100644 --- a/app/assets/stylesheets/r2_calculator.scss +++ b/app/assets/stylesheets/r2_calculator.scss @@ -1,5 +1,5 @@ #r2_calculator { - .row { - margin-top:1em; + .form-group { + margin-bottom:1em; } } From 64e59cd22fd18e86002165a57e5d4c11604e2cfa Mon Sep 17 00:00:00 2001 From: ColinBruce Date: Thu, 7 May 2015 10:38:58 +0100 Subject: [PATCH 9/9] Configured email validation on update --- app/models/user.rb | 2 +- app/views/users/edit.html.slim | 9 ++------- config/locales/en.yml | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 5563f2b73..eee15d92b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,7 +16,7 @@ class User < ActiveRecord::Base validates :role, :name, presence: true validates :email, format: { with: email_regex, - on: :create, + on: [:create, :update], allow_nil: true, message: I18n.t('dictionary.invalid_email', email: Settings.mail_tech_support) } diff --git a/app/views/users/edit.html.slim b/app/views/users/edit.html.slim index 16b343fe2..d7085baf3 100644 --- a/app/views/users/edit.html.slim +++ b/app/views/users/edit.html.slim @@ -1,14 +1,9 @@ -h2 Edit #{@user.email} +h2 Edit #{@user.name} = form_for @user do |f| - - if @user.errors.any? - #error_explanation - h2 = "#{pluralize(@user.errors.count, "error")} prohibited this user from being saved:" - ul - - @user.errors.full_messages.each do |message| - li = message .form-group + = f.label :email, @user.errors[:email].join(', ').html_safe, class: 'error' if @user.errors[:email].present? = f.label :email = f.text_field :email .form-group diff --git a/config/locales/en.yml b/config/locales/en.yml index dec0c1f67..7275748d3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -37,7 +37,6 @@ en: attributes: email: blank: 'Enter your email address' - invalid: You must enter an @hmcts.gsi.gov.uk email address not_found: That email is not registered on our system name: blank: You must enter a name for the user