Skip to content

Commit 9676e08

Browse files
PAF-129/ PAF-128 - Fix bug to add country from list and validate country textbox. (#96)
* PAF-128 & PAF-129 Added validation for phone and country textbox [PAF- 129](https://collaboration.homeoffice.gov.uk/jira/browse/PAF-129) All 'Country' fields allow any text without the use of drop down list [PAF-128](https://collaboration.homeoffice.gov.uk/jira/browse/PAF-128 URL's are being accepted in all free text fields - added validation rules to all countries fields in field/index.js - added dependent property to avoid error message when yes is selected on another location Tested manually * add behaviour to unset values
1 parent abfac19 commit 9676e08

File tree

4 files changed

+76
-7
lines changed

4 files changed

+76
-7
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
4+
module.exports = superclass => class extends superclass {
5+
getValues(req) {
6+
req.sessionModel.unset('crime-location-country');
7+
req.sessionModel.unset('crime-another-location-country');
8+
return super.getValues.apply(this, arguments);
9+
}
10+
};

apps/paf/fields/index.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ module.exports = {
381381
'boat-country-departure': {
382382
mixin: 'select',
383383
className: ['typeahead', 'js-hidden'],
384+
validate: ['required', 'notUrl'],
384385
options:
385386
[{
386387
value: '',
@@ -415,6 +416,7 @@ module.exports = {
415416
'train-country-departure': {
416417
mixin: 'select',
417418
className: ['typeahead', 'js-hidden'],
419+
validate: ['required', 'notUrl'],
418420
options:
419421
[{
420422
value: '',
@@ -452,6 +454,7 @@ module.exports = {
452454
'airline-country-departure': {
453455
mixin: 'select',
454456
className: ['typeahead', 'js-hidden'],
457+
validate: ['required', 'notUrl'],
455458
options:
456459
[{
457460
value: '',
@@ -544,6 +547,7 @@ module.exports = {
544547
'crime-location-country': {
545548
mixin: 'select',
546549
className: ['typeahead', 'js-hidden'],
550+
validate: ['required', 'notUrl'],
547551
options:
548552
[{
549553
value: '',
@@ -591,7 +595,11 @@ module.exports = {
591595
},
592596
'crime-location-phone': {
593597
className: ['govuk-input', 'govuk-input--width-20'],
594-
validate: [{ type: 'maxlength', arguments: 20 }]
598+
validate: ['required', { type: 'maxlength', arguments: 20 }],
599+
dependent: {
600+
field: 'crime-location',
601+
value: 'yes'
602+
}
595603
},
596604
'crime-another-location': {
597605
isPageHeading: true,
@@ -607,6 +615,7 @@ module.exports = {
607615
'crime-another-location-country': {
608616
mixin: 'select',
609617
className: ['typeahead', 'js-hidden'],
618+
validate: ['required', 'notUrl'],
610619
options:
611620
[{
612621
value: '',
@@ -654,7 +663,11 @@ module.exports = {
654663
},
655664
'crime-another-location-phone': {
656665
className: ['govuk-input', 'govuk-input--width-20'],
657-
validate: [{ type: 'maxlength', arguments: 20 }]
666+
validate: ['required', { type: 'maxlength', arguments: 20 }],
667+
dependent: {
668+
field: 'crime-another-location',
669+
value: 'yes'
670+
}
658671
},
659672
'report-person': {
660673
mixin: 'radio-group',
@@ -756,6 +769,7 @@ module.exports = {
756769
'report-person-location-outside-uk-address-country': {
757770
mixin: 'select',
758771
className: ['typeahead', 'js-hidden'],
772+
validate: ['required', 'notUrl'],
759773
options:
760774
[{
761775
value: '',
@@ -782,6 +796,7 @@ module.exports = {
782796
'report-person-location-travel-to-uk-country': {
783797
mixin: 'select',
784798
className: ['typeahead', 'js-hidden'],
799+
validate: ['required', 'notUrl'],
785800
options:
786801
[{
787802
value: '',
@@ -803,7 +818,7 @@ module.exports = {
803818
},
804819
'report-person-location-phone': {
805820
className: ['govuk-input', 'govuk-input--width-20'],
806-
validate: [{ type: 'maxlength', arguments: 20 }]
821+
validate: ['required', { type: 'maxlength', arguments: 20 }]
807822
},
808823
'report-person-location-email': {
809824
validate: ['email', { type: 'maxlength', arguments: 100 }]
@@ -887,7 +902,7 @@ module.exports = {
887902
},
888903
'report-person-occupation-company-phone': {
889904
className: ['govuk-input', 'govuk-input--width-20'],
890-
validate: [{ type: 'maxlength', arguments: 20 }]
905+
validate: ['required', { type: 'maxlength', arguments: 20 }]
891906
},
892907
'report-person-occupation-company-manager': {
893908
mixin: 'input-text',
@@ -947,7 +962,7 @@ module.exports = {
947962
},
948963
'report-person-study-phone': {
949964
className: ['govuk-input', 'govuk-input--width-20'],
950-
validate: [{ type: 'maxlength', arguments: 20 }]
965+
validate: ['required', { type: 'maxlength', arguments: 20 }]
951966
},
952967
'report-person-study-email': {
953968
validate: ['email', { type: 'maxlength', arguments: 100 }]
@@ -1204,7 +1219,7 @@ module.exports = {
12041219
},
12051220
'company-phone': {
12061221
className: ['govuk-input', 'govuk-input--width-20'],
1207-
validate: [{ type: 'maxlength', arguments: 20 }]
1222+
validate: ['required', { type: 'maxlength', arguments: 20 }]
12081223
},
12091224
'company-email': {
12101225
formatter: ['removespaces'],

apps/paf/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ const addressFormatter = require('./behaviours/address-formatter');
1515
const additionalPersonFormatter = require('./behaviours/additional-person-formatter');
1616
const vehicleToggleFormatter = require('./behaviours/vehicle-toggle-formatter');
1717
const SendToSQS = require('./behaviours/send-to-sqs');
18+
const UnsetCrimeCountry = require('./behaviours/unset-crime-country');
1819
const timeFormatter = require('./behaviours/time-formatter');
1920

21+
2022
module.exports = {
2123
name: 'paf',
2224
baseUrl: '/paf',
@@ -261,7 +263,8 @@ module.exports = {
261263
field: 'crime-location',
262264
value: 'yes'
263265
}
264-
}]
266+
}],
267+
behaviours: [UnsetCrimeCountry]
265268
},
266269
'/crime-another-location': {
267270
fields: ['crime-another-location',

apps/paf/translations/src/en/validation.json

+41
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,19 @@
9393
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
9494
},
9595
"crime-location-phone": {
96+
"required": "Enter a valid phone number",
97+
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
98+
},
99+
100+
"report-person-study-phone": {
101+
"required": "Enter a valid phone number",
96102
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
97103
},
98104
"crime-another-location-address-postcode": {
99105
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
100106
},
101107
"crime-another-location-phone": {
108+
"required": "Enter a valid phone number",
102109
"maxlength": "You can't use more than {{maxlength}} numbers for your answer"
103110
},
104111
"report-person-first-name": {
@@ -135,6 +142,7 @@
135142
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
136143
},
137144
"report-person-location-phone": {
145+
"required": "Enter a valid phone number",
138146
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
139147
},
140148
"report-person-location-email": {
@@ -161,6 +169,11 @@
161169
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
162170
},
163171
"report-person-occupation-company-phone": {
172+
"required": "Enter a valid phone number",
173+
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
174+
},
175+
"company-phone": {
176+
"required": "Enter a valid phone number",
164177
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
165178
},
166179
"report-person-occupation-company-manager": {
@@ -305,6 +318,34 @@
305318
"when-to-contact": {
306319
"maxlength": "You can't use more than {{maxlength}} characters for your answer"
307320
},
321+
"boat-country-departure": {
322+
"required": "Enter a valid country",
323+
"notUrl": "Enter a valid country on the list"
324+
},
325+
"airline-country-departure": {
326+
"required": "Enter a valid country",
327+
"notUrl": "Enter a valid country on the list"
328+
},
329+
"crime-location-country": {
330+
"required": "Enter a valid country",
331+
"notUrl": "Enter a valid country on the list"
332+
},
333+
"crime-another-location-country": {
334+
"required": "Enter a valid country",
335+
"notUrl": "Enter a valid country on the list"
336+
},
337+
"train-country-departure": {
338+
"required": "Enter a valid country",
339+
"notUrl": "Enter a valid country on the list"
340+
},
341+
"report-person-location-outside-uk-address-country": {
342+
"required": "Enter a valid country",
343+
"notUrl": "Enter a valid country on the list"
344+
},
345+
"report-person-location-travel-to-uk-country": {
346+
"required": "Enter a valid country",
347+
"notUrl": "Enter a valid country on the list"
348+
},
308349
"other-info-file-upload": {
309350
"maxFileSize": "Select a file that is smaller than 100 MB",
310351
"fileType": "This file is not a valid file format you can upload to this service."

0 commit comments

Comments
 (0)