File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,17 @@ schema: 2
33name : Payment Test Form
44declaration : " <p class=\" govuk-body\" >All the answers you have provided are true to the best of your knowledge.</p>"
55pages :
6+ - title : What is your name?
7+ path : ' /person'
8+ components :
9+ - name : personName
10+ title : What is your name?
11+ type : TextField
12+ shortDescription : Your name
13+ options :
14+ required : true
15+ next :
16+ - path : ' /pay-for-your-licence'
617 - title : A page title
718 path : ' /pay-for-your-licence'
819 components :
2839conditions : []
2940sections : []
3041lists : []
31- startPage : ' /pay-for-your-licence '
42+ startPage : ' /person '
Original file line number Diff line number Diff line change @@ -68,7 +68,10 @@ export class PaymentField extends FormComponent {
6868 . label ( this . label )
6969
7070 this . formSchema = paymentStateSchema
71- this . stateSchema = paymentStateSchema . default ( null ) . allow ( null )
71+ // 'required()' forces the payment page to be invalid until we have valid payment state
72+ // i.e. the user will automatically be directed back to the payment page
73+ // if they attempt to access future pages wen no payment entered yet
74+ this . stateSchema = paymentStateSchema . required ( )
7275 }
7376
7477 /**
Original file line number Diff line number Diff line change @@ -29,7 +29,6 @@ import { Parser, type Value } from 'expr-eval-fork'
2929import joi from 'joi'
3030
3131import { createLogger } from '~/src/server/common/helpers/logging/logger.js'
32- import { type ComponentCollection } from '~/src/server/plugins/engine/components/ComponentCollection.js'
3332import { type ListFormComponent } from '~/src/server/plugins/engine/components/ListFormComponent.js'
3433import { } from '~/src/server/plugins/engine/components/YesNoField.js'
3534import {
@@ -521,30 +520,15 @@ export class FormModel {
521520 }
522521 }
523522
524- private isUnpaidPayment (
525- context : FormContext ,
526- collection : ComponentCollection
527- ) {
528- const paymentField = collection . fields . find (
529- ( field ) => field . type === ComponentType . PaymentField
530- )
531- if ( paymentField ) {
532- const fieldVal = paymentField . getFormValueFromState ( context . state )
533- return fieldVal === undefined
534- }
535- return false
536- }
537-
538523 private assignPaths ( context : FormContext ) {
539- for ( const { keys, path, collection } of context . relevantPages ) {
524+ for ( const { keys, path } of context . relevantPages ) {
540525 context . paths . push ( path )
541526
542527 // Stop at page with errors
543528 if (
544529 context . errors ?. some ( ( { name, path } ) => {
545530 return keys . includes ( name ) || keys . some ( ( key ) => path . includes ( key ) )
546- } ) ||
547- this . isUnpaidPayment ( context , collection )
531+ } )
548532 ) {
549533 break
550534 }
You can’t perform that action at this time.
0 commit comments