Description
I created an exemple to reproduce the behavior.
http://codepen.io/anon/pen/RRVQpv?editors=1010
If the input overextends the limit we have three errors
{
"schemaForm": true,
"md-maxlength": true,
"tv4-201": true
}
If we remove some characters until we reach the limit, 200 characters in my example.
The field remains invalid.
Proposition :
I think the problem comes from a remaining schemaForm
error set by angular-schema-form.
I looked at its code and I saw two interesting lines used for validation :
// Any error and we're out of here!
return !Object.keys(ngModel.$error).some(function(e) { return e !== 'schemaForm';});
// In Angular 1.3 we use one $validator to stop the model value from getting updated.
// this means that we always end up with a 'schemaForm' error.
errors = errors.filter(function(e) { return e !== 'schemaForm'; });
Changing e !== 'schemaForm';
by error.indexOf('tv4-') === 0
fixed the problem.
Basically if we don't have an error from tv4 validation, we ignore it.
(It also fixes an error on textarea error messages because md-maxlength
error is also ignored. I'll have a PR for this soon)
However I guess it breaks any custom validation --> https://github.com/json-schema-form/angular-schema-form/blob/development/docs/index.md#custom-validation
Does anyone have a better fix idea for this problem ?