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

Bad validation message #3914

Open
jma opened this issue May 16, 2024 · 7 comments · Fixed by #3939
Open

Bad validation message #3914

jma opened this issue May 16, 2024 · 7 comments · Fixed by #3939
Labels

Comments

@jma
Copy link

jma commented May 16, 2024

Description
A wrong validation message is displayed with arrays.

Minimal Reproduction

Here you can find a stackblitz reproduction example. If you click on submit we got a required error message instead of a minLength. Let us know if we need to open an issue.

https://stackblitz.com/edit/angular-kwmyzs-pmxgrs?file=src%2Fassets%2Fjson-schema%2Farrays.json

Thanks in advance.

@jma jma added the bug label May 16, 2024
@aitboudad aitboudad added question and removed bug labels May 26, 2024
@aitboudad
Copy link
Member

it is required to pass an empty string for that case, if I'm not wrong. Please try the following solution instead:

"items": {
  "type": "string",
  "minLength": 0,
+ "default": ""
}

@jma
Copy link
Author

jma commented Jun 5, 2024

Unfortunately, this does not work. Here is a modified example:

https://stackblitz.com/edit/angular-kwmyzs-pmxgrs?file=src%2Fassets%2Fjson-schema%2Farrays.json

@aitboudad aitboudad reopened this Jun 5, 2024
@jma
Copy link
Author

jma commented Jun 5, 2024

In fact a field with an parent field of type array should never be required at least for a JSONScheam. The required property is only available on the object type thus only for the children of an object field. I tried to add a patch in the prePopulate of my extension, but changing the required property of a field change also the required property of the children...

@aitboudad
Copy link
Member

This issue has been fixed and released as part of v6.3.4 release.

Please let us know, in case you are still encountering a similar issue/problem.
Thank you!

@jma
Copy link
Author

jma commented Jun 10, 2024

This issue has been fixed and released as part of v6.3.4 release.

Please let us know, in case you are still encountering a similar issue/problem. Thank you!

Unfortunately this is the case. You have introduce a new bug in the version 6.3.4. Using the following stackblitz example the field "new" is not marked as required anymore:
https://stackblitz.com/edit/angular-kwmyzs-1aw4z2?file=src%2Fassets%2Fjson-schema%2Farrays.json

Thanks in advance.

@aitboudad aitboudad reopened this Jun 10, 2024
@aitboudad
Copy link
Member

https://stackblitz.com/edit/angular-kwmyzs-1aw4z2?file=src%2Fassets%2Fjson-schema%2Farrays.json

The issue here is when/in which case an array item is considered required. here is how it is handled:

  • Object is underlined, name field is not required
  • Object set, name field is required

@jma
Copy link
Author

jma commented Jun 11, 2024

The issue here is when/in which case an array item is considered required. here is how it is handled:

  • Object is underlined, name field is not required
  • Object set, name field is required

If I understood well, you want to make a input field required only when a field is touch, but we have several problems here. Running the following modified example:
https://stackblitz.com/edit/angular-kwmyzs-1aw4z2?file=src%2Fassets%2Fjson-schema%2Farrays.json

  1. after loading the editor is ok
  2. after clicking on "submit" the validation message is wrong: the array is not required but need at least one item, thus the error message "This field is required" is wrong.
  3. now if a new item is added, we can see that the form is valid which is not true, if we try to validate the model against the JOSONSchema, the "new" property is missing as it is required.
  4. If I enter a "space" in the "new" field and suppress it (the field is touched), the message "This field is required" appears but I cannot go back to the situation before I touched the field.

Thanks in advance for your reply.

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

Successfully merging a pull request may close this issue.

2 participants