-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: working and adjusted concardis-directdebit validation (#590)
- Loading branch information
Showing
19 changed files
with
121 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/app/pages/checkout-payment/formly/server-validation.extension.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { FormControl } from '@angular/forms'; | ||
import { FormlyExtension, FormlyFieldConfig } from '@ngx-formly/core'; | ||
|
||
/** | ||
* Extension to enable server-side validation. | ||
* It accesses the formstate with two properties: errors and changedSinceErrors. | ||
* If these are set for a property, it will have an error. | ||
* To use this extension, set the formState in the relevant component. | ||
*/ | ||
export const serverValidationExtension: FormlyExtension = { | ||
prePopulate: field => { | ||
if (field.hide) { | ||
return; | ||
} | ||
field.templateOptions = { | ||
...field.templateOptions, | ||
showValidation: (fld: FormlyFieldConfig) => | ||
field.formControl?.valid && | ||
field.formControl?.dirty && | ||
!field.options.formState.changedSinceErrors?.[fld.key as string], | ||
}; | ||
|
||
field.validators = { | ||
...field.validators, | ||
serverError: (_: FormControl, fld: FormlyFieldConfig) => | ||
!( | ||
fld.options.formState.errors?.[fld.key as string] && | ||
fld.options.formState.changedSinceErrors?.[fld.key as string] === false | ||
), | ||
}; | ||
|
||
field.validation = { | ||
...field.validation, | ||
messages: { | ||
...field.validation?.messages, | ||
serverError: '', | ||
}, | ||
}; | ||
|
||
field.expressionProperties = { | ||
...field.expressionProperties, | ||
'validation.messages.serverError': (_, formState) => formState.errors?.[field.key as string], | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters