angular-schema-form-material icon indicating copy to clipboard operation
angular-schema-form-material copied to clipboard

Inacurate textarea maxlength error

Open RudolfFrederiksen opened this issue 8 years ago • 2 comments

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 ?

RudolfFrederiksen avatar Jul 01 '16 13:07 RudolfFrederiksen

@RudolfFrederiksen I don't know many others using the Material Design decorator yet, still needs a lot of work, but frankly starting to wonder if most of that effort would be better spent on ng2 and Angular Material 2.

I would love any help/suggestions/PRs you can provide! It is hard to try to run so many repos in my spare time!

Anthropic avatar Jul 03 '16 09:07 Anthropic

@RudolfFrederiksen spot on with your evaluation, but I can't change the behaviour in that file without breaking the bootstrap decorator also!! So I have to find a middleground.

The following change will also fix the issue with reduced impact, but I don't like it as it would require more work for every custom decorator to not cause the same issue with any other validation. .filter(function(k) { return k.indexOf('tv4-') === 0 || k.indexOf('md-') === 0; }) in schemaValidate.js#49

Anthropic avatar Jul 10 '16 13:07 Anthropic