I am using NGX-Schema-Form https://github.com/makinacorpus/ngx-schema-form to render form fields based on a json object.
My question is: How to add custom validation error messages to my schema and also how to display them properly on the ui (Bootstrap 4.1 based
).
Here is an example of the standard schema format:
Note: Pattern, minLength, maxLength
mySchema = {
"properties": {
"cellphoneNumber": {
"type": "string",
"title": "Cellphone number",
"placeholder": "e.g. 082 320 2121",
"widget": {
"id": "string"
},
"pattern": "^\\d{10}$",
"minLength": 5,
"maxLength": 12
}
}
But what i would like to do:
mySchema = {
"properties": {
"cellphoneNumber": {
"type": "string",
"title": "Cellphone number",
"placeholder": "e.g. 082 320 2121",
"widget": {
"id": "string"
},
pattern: {
value: '^\\d{10}$',
message: 'Cellphone number must be 10 digits'
},
minLength: {
value: '5',
message: 'Please enter at least 5 characters'
}
maxLength: {
value: '14',
message: 'Please enter no more than least 14 characters'
}
}
}
Any ideas?
And then also how to override the standard string widget to show this error if the form and field is ng-dirty and ng-touched.
Rough example:
<div class="error mt-2" *ngIf="control.errors && control.pristine == false || control.touched == true">
<div *ngFor="let err of control.errors">
{{ err.message }}
</div>
</div>
Im am looking for a solid solution please for enterprise level implementation.