From d9c95f6d658210bccd35e9a41c2bdce113d11743 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 7 Sep 2022 17:35:05 +0100 Subject: [PATCH] feat: validate local authority to not be nil or "Select an option" --- app/controllers/locations_controller.rb | 22 ++++++++++++++----- .../locations/edit_local_authority.html.erb | 2 +- config/locales/en.yml | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index f57fb6b4d..ccd80d9cf 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -70,13 +70,19 @@ class LocationsController < ApplicationController when "edit-name" redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) when "edit-local-authority" - @uri_query = URI.parse(request.referer).query - @query_hash = @uri_query ? CGI.parse(@uri_query) : { "add_another_location": [] } - @add_another_location = @query_hash["add_another_location"].try(:first) - if @add_another_location == "Yes" - redirect_to(new_location_path(@location.scheme)) + if valid_location_admin_district?(location_params) + @uri_query = URI.parse(request.referer).query + @query_hash = @uri_query ? CGI.parse(@uri_query) : { "add_another_location": [] } + @add_another_location = @query_hash["add_another_location"].try(:first) + if @add_another_location == "Yes" + redirect_to(new_location_path(@location.scheme)) + else + redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) + end else - redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) + error_message = I18n.t("validations.location_admin_district") + @location.errors.add :location_admin_district, error_message + render :edit_local_authority, status: :unprocessable_entity end end else @@ -130,4 +136,8 @@ private def search_term params["search"] end + + def valid_location_admin_district?(location_params) + location_params["location_admin_district"] != "Select an option" + end end diff --git a/app/views/locations/edit_local_authority.html.erb b/app/views/locations/edit_local_authority.html.erb index 6c0224732..51894ab89 100644 --- a/app/views/locations/edit_local_authority.html.erb +++ b/app/views/locations/edit_local_authority.html.erb @@ -12,7 +12,7 @@ <%= render partial: "organisations/headings", locals: { main: "What is the the local authority of #{@location.postcode}?", sub: @scheme.service_name } %> - <% la_list = ["Adur", "Allerdale", "Amber Valley", "Arun", "Ashfield", "Ashford", "Babergh", "Barking and Dagenham", "Barnet", "Barnsley", "Barrow-in-Furness", "Basildon", "Basingstoke and Deane", "Bassetlaw", "Bath and North East Somerset", "Bedford", "Bexley", "Birmingham", "Blaby", "Blackburn with Darwen", "Blackpool", "Bolsover", "Bolton", "Boston", "Bournemouth, Christchurch and Poole", "Bracknell Forest", "Bradford", "Braintree", "Breckland", "Brent", "Brentwood", "Brighton and Hove", "Bristol, City of", "Broadland", "Bromley", "Bromsgrove", "Broxbourne", "Broxtowe", "Buckinghamshire", "Burnley", "Bury", "Calderdale", "Cambridge", "Camden", "Cannock Chase", "Canterbury", "Carlisle", "Castle Point", "Central Bedfordshire", "Charnwood", "Chelmsford", "Cheltenham", "Cherwell", "Cheshire East", "Cheshire West and Chester", "Chesterfield", "Chichester", "Chorley", "City of London", "Colchester", "Copeland", "Corby", "Cornwall", "Cotswold", "County Durham", "Coventry", "Craven", "Crawley", "Croydon", "Dacorum", "Darlington", "Dartford", "Daventry", "Derby", "Derbyshire Dales", "Doncaster", "Dorset", "Dover", "Dudley", "Ealing", "East Cambridgeshire", "East Devon", "East Hampshire", "East Hertfordshire", "East Lindsey", "East Northamptonshire", "East Riding of Yorkshire", "East Staffordshire", "East Suffolk", "Eastbourne", "Eastleigh", "Eden", "Elmbridge", "Enfield", "Epping Forest", "Epsom and Ewell", "Erewash", "Exeter", "Fareham", "Fenland", "Folkestone and Hythe", "Forest of Dean", "Fylde", "Gateshead", "Gedling", "Gloucester", "Gosport", "Gravesham", "Great Yarmouth", "Greenwich", "Guildford", "Gwynedd", "Hackney", "Halton", "Hambleton", "Hammersmith and Fulham", "Harborough", "Haringey", "Harlow", "Harrogate", "Harrow", "Hart", "Hartlepool", "Hastings", "Havant", "Havering", "Herefordshire, County of", "Hertsmere", "High Peak", "Highland", "Hillingdon", "Hinckley and Bosworth", "Horsham", "Hounslow", "Huntingdonshire", "Hyndburn", "Ipswich", "Isle of Wight", "Isles of Scilly", "Islington", "Kensington and Chelsea", "Kettering", "King's Lynn and West Norfolk", "Kingston upon Hull, City of", "Kingston upon Thames", "Kirklees", "Knowsley", "Lambeth", "Lancaster", "Leeds", "Leicester", "Lewes", "Lewisham", "Lichfield", "Lincoln", "Liverpool", "Luton", "Maidstone", "Maldon", "Malvern Hills", "Manchester", "Mansfield", "Medway", "Melton", "Mendip", "Merton", "Mid Devon", "Mid Suffolk", "Mid Sussex", "Middlesbrough", "Milton Keynes", "Mole Valley", "New Forest", "Newark and Sherwood", "Newcastle upon Tyne", "Newcastle-under-Lyme", "Newham", "North Devon", "North East Derbyshire", "North East Lincolnshire", "North Hertfordshire", "North Kesteven", "North Lincolnshire", "North Norfolk", "North Somerset", "North Tyneside", "North Warwickshire", "North West Leicestershire", "Northampton", "Northumberland", "Norwich", "Nottingham", "Nuneaton and Bedworth", "Oadby and Wigston", "Oldham", "Oxford", "Pendle", "Peterborough", "Plymouth", "Portsmouth", "Preston", "Reading", "Redbridge", "Redcar and Cleveland", "Redditch", "Reigate and Banstead", "Ribble Valley", "Richmond upon Thames", "Richmondshire", "Rochdale", "Rochford", "Rossendale", "Rother", "Rotherham", "Rugby", "Runnymede", "Rushcliffe", "Rushmoor", "Rutland", "Ryedale", "Salford", "Sandwell", "Scarborough", "Sedgemoor", "Sefton", "Selby", "Sevenoaks", "Sheffield", "Shropshire", "Slough", "Solihull", "Somerset West and Taunton", "South Cambridgeshire", "South Derbyshire", "South Gloucestershire", "South Hams", "South Holland", "South Kesteven", "South Lakeland", "South Norfolk", "South Northamptonshire", "South Oxfordshire", "South Ribble", "South Somerset", "South Staffordshire", "South Tyneside", "Southampton", "Southend-on-Sea", "Southwark", "Spelthorne", "St Albans", "St. Helens", "Stafford", "Staffordshire Moorlands", "Stevenage", "Stockport", "Stockton-on-Tees", "Stoke-on-Trent", "Stratford-on-Avon", "Stroud", "Sunderland", "Surrey Heath", "Sutton", "Swale", "Swindon", "Tameside", "Tamworth", "Tandridge", "Teignbridge", "Telford and Wrekin", "Tendring", "Test Valley","Tewkesbury", "Thanet", "Three Rivers", "Thurrock", "Tonbridge and Malling", "Torbay", "Torridge", "Tower Hamlets", "Trafford", "Tunbridge Wells", "Uttlesford", "Vale of White Horse", "Wakefield", "Walsall", "Waltham Forest", "Wandsworth", "Warrington", "Warwick", "Watford", "Waverley", "Wealden", "Wellingborough", "Welwyn Hatfield", "West Berkshire", "West Devon", "West Lancashire", "West Lindsey", "West Oxfordshire", "West Suffolk", "Westminster", "Wigan", "Wiltshire", "Winchester", "Windsor and Maidenhead", "Wirral", "Woking", "Wokingham", "Wolverhampton", "Worcester", "Worthing", "Wychavon", "Wyre", "Wyre Forest", "York"] %> + <% la_list = FormHandler.instance.current_form.get_question("la", nil).answer_options.values %> <% las = la_list.map { |la| OpenStruct.new(name: la) } %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c6403408c..171db83bd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -104,6 +104,7 @@ en: invalid_date: "Enter a date in the correct format, for example 31 1 2022" outside_collection_window: "Enter a date within the current collection windows" postcode: "Enter a postcode in the correct format, for example AA1 1AA" + location_admin_district: "Select a local authority" email: taken: "Enter an email address that hasn’t already been used to sign up" invalid: "Enter an email address in the correct format, like name@example.com"