Required nested properties valid even though they are empty
See original GitHub issueWe are using the library to generate forms for tasks configured by users as part of scientific workflows.
Our schemas usually consist of a taskName
property (string), and a parameters
property (object with nested properties), for example:
{ "properties": {
"taskName": {
"type": "string",
"title": "Task name",
"description": "(required)",
"placeholder": "Enter a name for this task"
},
"parameters": {
"type": "object",
"description": "Parameters",
"properties": {
"paramA": {
"type": "string",
"title": "Param A",
"description": "(required)"
},
"paramB": {
"type": "string",
"title": "Param B",
"description": "(not required)"
}
},
"required": ["paramA"]
}
},
"required": ["taskName", "parameters"]
}
In this case, top level property taskName
is required, as is nested property paramA
.
Our issue is that required nested properties have the class has-success
, with the input having the class ng-valid
even though they are empty. But validation seems to be working, since errors for missing property paramA
are displayed.
This prevents us from using the has-error/has-success
or ng-valid/ng-invalid
classes to inform the user about which fields are valid and which are not.
On the other hand, top level property taskName
has the class 'has-error", with the input having the class ng-invalid
as expected when empty.
Stackblitz reproducing the issue
Are we missing something here, or is it a bug?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7
Top GitHub Comments
Thank you @daniele-pecora for your quick answer, will try to customize the validator. Nice working sample btw, I will use them in the future 😃
Answer Create a custom schema validator that corrects the error message path, so the error is mapped to the field itself. Working sample: custom-zschema-validator-factory.ts
Answer Create a custom schema validator that ignores the error if the field is not required. Working sample: fix-optional-empty-fields-z-schema-validator-factory.ts
Usage working sample https://github.com/daniele-pecora/ngx-schema-form-widgets-material