Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASF doesn't validate properties that are absent from the form #957

Open
donalmurtagh opened this issue Mar 6, 2018 · 6 comments
Open

ASF doesn't validate properties that are absent from the form #957

donalmurtagh opened this issue Mar 6, 2018 · 6 comments

Comments

@donalmurtagh
Copy link
Contributor

donalmurtagh commented Mar 6, 2018

Expected behaviour

If a property that is defined as required in the schema, is absent from the form (and model), the model should fail validation

Actual 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

@Anthropic
Copy link
Member

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.

@donalmurtagh
Copy link
Contributor Author

@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.

@Anthropic
Copy link
Member

@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.

@Anthropic
Copy link
Member

@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 :)

@Flicksi
Copy link

Flicksi commented Jul 2, 2018

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.

@Anthropic
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants