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

Validators not updating when dependant on other form values #287

Open
codeuniquely opened this issue Jul 4, 2017 · 2 comments
Open

Validators not updating when dependant on other form values #287

codeuniquely opened this issue Jul 4, 2017 · 2 comments

Comments

@codeuniquely
Copy link

codeuniquely commented Jul 4, 2017

I have set up a 'plnker' to demonstrate a common issue when users fill in forms, that have values later on that are dependant on and validated by values put into previous inputs. Please see the following:
https://plnkr.co/edit/ELplnBCAUjatpusW6EPU?p=preview

Enter some values - for example

10
Hello World
15

and you will get the warning AFTER the second Number of - 'A maximum value of 10 is allowed.'

If you now tab back UP the form or just click into the first input and enter a value of 100 instead and blur out of that control into the next one - then the value in form.value1 is updated. However the validation does not see the update and still continues to show an error messages - even hough its input is now actually valid (and its label and validator have both been updated) ....

How do you get the validation to fire again for the seconds input so that the error message goes away ... ?????

@codeuniquely codeuniquely changed the title Validations not updating when dependant on other form values Validators not updating when dependant on other form values Jul 4, 2017
@codeuniquely
Copy link
Author

I think there is a fix for this

There is already an $observe on the validator - which updates it and we could use this to re-run the validation rule after...

current code

/**
  * Observe validator changes in order to allow dynamically change it
  */
  attrs.$observe('validator', function(value) {
  validation = value.split(',');
});

if this was updated to also make a call back to checkValidation then the error messages would automatically be removed once the conditions on the later validation have been met

Suggestion:

/**
  * Observe validator changes in order to allow dynamically change it
  */
  attrs.$observe('validator', function(value) {
  validation = value.split(',');
  // validation has been updated => make the validation fire again
  var theValue = useViewValue ? ctrl.$viewValue : ctrl.$modelValue;
  checkValidation(scope, element, attrs, ctrl, validation, theValue);
});

@codeuniquely
Copy link
Author

It appears to work - in my code - does this effect / break anything else ?

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

No branches or pull requests

1 participant