Open donalmurtagh opened 6 years ago
Hi @donalmurtagh I'm not sure exactly why it was done this way, but to my understanding of the history it was determined that only what is available should be validated. I suspect this was due to limitations in tv4 and the integration with angular required to handle the validations.
I expect that with the swappable validators when I finish them there will be an option to handle this given the more useful feedback that the framework provides. In the meantime running validation of the full schema against the data on submit would handle the issue, but would not highlight the missing field obviously. Actually I think that was the other reason it was not done that way, so there wouldn't be errors the end user could not resolve.
@Anthropic thanks for your response. I agree that visually highlighting validation errors for non-existent fields is obviously impossible, but equally, I'm uneasy about a model that does not conform to the schema passing validation. One possible solution would be for validation to throw an error in such cases, alerting the developer to the fact that there's an error in their form implementation.
In other words, the correct response, should be to alert the developer of the problem, rather than the user completing the form.
@donalmurtagh sorry for the delay I got so sick I ended up in hospital, back to normal life again now, yes I fully agree with you, the problem being I don't have enough co-developers so there isn't much I can do till I iron out the issues I am having with the new version and can do away with tv4. Then I can get enough info that I may be able to provide that sort of option.
@donalmurtagh just as a secondary thought, there is no reason that the whole data object cannot be validated against the whole schema, this would be easy to implement given all the libs are already loaded. A directive added to the form could do it and could be included within your development build and not in prod. Just a thought while I was cleaning up issues :)
There is a situation, where this behaviour is not wrong. If you only show a field under certain conditions, it usually is a required field. Because you need some extra information or something like that. But if the condition to show the field isn't met, it is not required.
@Flicksi yes, I do intend on providing, eventually, the ability to change certain attributes based on rules, can't say when though, need to discuss it more with other json-schema members.
Expected behaviour
If a property that is defined as
required
in the schema, is absent from the form (and model), the model should fail validationActual behaviour
The model passes validation
Gist/Plunker/Demo
This demo modifies the simple example by adding a required
name2
property to the schema. Notice that validation passes, even though neither the form nor the model contain this property.@json-schema-form/angular-schema-form-lead