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

Inacurate textarea maxlength error #21

Open
RudolfFrederiksen opened this issue Jul 1, 2016 · 2 comments
Open

Inacurate textarea maxlength error #21

RudolfFrederiksen opened this issue Jul 1, 2016 · 2 comments

Comments

@RudolfFrederiksen
Copy link
Contributor

RudolfFrederiksen commented Jul 1, 2016

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 RudolfFrederiksen changed the title Innacurate textarea maxlength error Inacurate textarea maxlength error Jul 1, 2016
@Anthropic
Copy link
Member

@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
Copy link
Member

@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

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

2 participants