Browse Source

feat: validate local authority to not be nil or "Select an option"

CLDC-1390-la-lookup-fallback-WIP
natdeanlewissoftwire 2 years ago
parent
commit
d9c95f6d65
  1. 10
      app/controllers/locations_controller.rb
  2. 2
      app/views/locations/edit_local_authority.html.erb
  3. 1
      config/locales/en.yml

10
app/controllers/locations_controller.rb

@ -70,6 +70,7 @@ class LocationsController < ApplicationController
when "edit-name"
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
when "edit-local-authority"
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)
@ -78,6 +79,11 @@ class LocationsController < ApplicationController
else
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations"))
end
else
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
render :edit, status: :unprocessable_entity
@ -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

2
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) } %>

1
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"

Loading…
Cancel
Save