minLength validation not working in array items
In the example below, a minLength of 1 is set on the array items, but the form allows submission with an empty array item field.
http://schemaform.io/examples/bootstrap-example.html#/67dd0bb3fbacee29cd39
However, if I set items to be objects and set the name field to be required, then it will work, but that leaves the form looking odd.
http://schemaform.io/examples/bootstrap-example.html#/c6e3ec60d055408d74e9
Looks to me like it's working for array items the same as everywhere else. The problem seems to be that it doesn't report an empty string field as failing the validation. It only starts checking minLength when at least one character has been entered.
There is a bug in minLength validation (I've submitted pull request #486 for that) but even with that fixed the problem persists.
OK, so I've found the problem. The validator sets 0 length string values to be undefined. I added console.log(data, typeof data, data.length); at the top of the tv4 validateStringLength function and found that strings are passed as expected when they have length:
{0: "test"} "object" undefined
test string 4
But when the undefined is passed, it creates a 0 length object, which tv4 returns null.
{} "object" undefined
Changing the angular-schema-form validate function to remove the empty string undefined conversion solves the problem:
{0: ""} "object" undefined
string 0
It does not seem to break validation on any of the other required fields as the comments above the conversion suggest, but I don't have an in depth knowledge of the plugin, so I could be missing something.
So the above only fixes minLength checks on keyboard input, the issue is still present on form submission.
http://schemaform.io/examples/bootstrap-example.html#/a8016f12f91cc910b115
The form above does not follow the JSON Schema as it allows the empty Column field to be submitted. If you paste the schema and the model into http://jsonschemalint.com it correctly identifies the error, even if you change the model value from null to "".
+1 for this fix
Another +1
+1
+1
+1 for someone submitting a PR. :-)