@@ -19,8 +19,6 @@ import {
1919 scrollToError ,
2020 getPathParams ,
2121 hiddenFields ,
22- GBPostCodePattern ,
23- OverseasPostCodePattern ,
2422 justInTimeLinkText ,
2523 validateForm ,
2624 getFieldValidations ,
@@ -40,12 +38,6 @@ function GiftAid(props) {
4038 const [ formValidityState , setFormValidityState ] = useState ( initialFormValidity ) ; // intitialise form validity states
4139 const [ fieldValidation , setFieldValidation ] = useState ( getFieldValidations ( update ) ) ; // intitialise field validation state based on form type
4240 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
43- // As GB is the default country, set the matching postcode regex pattern as default too
44- const [ currentPostcodePattern , setCurrentPostcodePattern ] = useState ( GBPostCodePattern ) ;
45-
46- // Simple counter to allow us to trigger the child 'revalidate postcode' function after regex updates
47- const [ postcodeRevalidate , setPostcodeRevalidate ] = useState ( 0 ) ;
48-
4941 const inputRef = useRef ( null ) ;
5042
5143 // initialise URL token state if available
@@ -79,29 +71,6 @@ function GiftAid(props) {
7971 }
8072 } , [ ] ) ;
8173
82- /**
83- * Crummy workaround to trigger a revalidation
84- * as the bespoke validation here has issues
85- */
86- const revalidatePostcode = ( ) => {
87- // Store the current postcode to re-add
88- const postcodeField = document . getElementById ( "field-input--postcode" ) ;
89- const currentPostcodeValue = postcodeField . value ;
90- const blurEvent = new Event ( 'blur' , { bubbles : true } ) ;
91-
92- // Temporarily reset the postcode field and programmatically
93- // trigger a blur event to make the validation take notice
94- postcodeField . value = '' ;
95- postcodeField . dispatchEvent ( blurEvent ) ;
96-
97- setTimeout ( ( ) => {
98- // Immediately re-add the value and trigger another blur event
99- postcodeField . value = currentPostcodeValue ;
100- postcodeField . dispatchEvent ( blurEvent ) ;
101- } , 1 ) ;
102- } ;
103-
104-
10574 /**
10675 * Fetches decrypted MSISDN using token
10776 * @param cipherText
@@ -151,20 +120,6 @@ function GiftAid(props) {
151120 ( thisFieldsState . fieldValidation !== thisFieldsPreviousState . fieldValidation ) ;
152121
153122 if ( ( thisFieldsPreviousState && isUpdatedState ) || marketingConsentFieldsChanged === true ) {
154-
155- // Update postcode regex is 'Country' select value has changed
156- if ( thisFieldsName === 'country' && thisFieldsState . value !== thisFieldsPreviousState . value ) {
157-
158- // Ignore the on-mount validation call
159- if ( thisFieldsPreviousState . value !== undefined ) {
160- // Switch regex patterns accordingly; if a non-GB value, this undefined value
161- // will cause the PCLU to fallback to its default, much looser regex
162- setCurrentPostcodePattern ( thisFieldsState . value === 'GB' ? GBPostCodePattern : undefined ) ;
163- // Call our workaround to trigger a revalidation of the PCLU postcode field
164- revalidatePostcode ( ) ;
165- }
166- }
167-
168123 // Reset url transaction Id state
169124 if ( thisFieldsName === 'transactionId' && thisFieldsState . valid ) {
170125 setFormValidityState ( {
@@ -226,7 +181,6 @@ function GiftAid(props) {
226181 const contextProps = {
227182 urlTransactionId,
228183 hiddenFields,
229- currentPostcodePattern,
230184 justInTimeLinkText,
231185 formValidityState,
232186 fieldValidation,
@@ -249,7 +203,6 @@ function GiftAid(props) {
249203 < SubmitForm
250204 title = "Submit Form"
251205 msisdn = { msisdn }
252- postcodeRevalidate = { postcodeRevalidate }
253206 />
254207 ) }
255208 </ FormProvider >
0 commit comments