Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngModelOptions): add validateOn option #7414

Closed
wants to merge 1 commit into from
Closed

feat(ngModelOptions): add validateOn option #7414

wants to merge 1 commit into from

Conversation

shahata
Copy link
Contributor

@shahata shahata commented May 9, 2014

Add option to set different triggers for validation than the triggers that actually update the model. A new method $$validateViewValue was extracted from $commitViewValue which can be called when a validateOn trigger occurs. This method sets the control as dirty and runs all $parsers, but doesn't actually change the model. The idea is that many times people want to pend or debounce the updates to the model in order to prevent a lot of invocations of watchers or just simply to update their model only when a form is submitted, but they would still like their users to get feedback immediately when the view is dirty or invalid.

BREAKING CHANGE:

This commit introduces the option to run $parsers without setting the $modelValue with the result.

Closes #7016

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#7414)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@shahata shahata added cla: yes and removed cla: no labels May 12, 2014
@IgorMinar
Copy link
Contributor

The idea is that many times people want to pend or debounce the updates to the model in order to prevent a lot of invocations of watchers or just simply to update their model only when a form is submitted, but they would still like their users to get feedback immediately when the view is dirty or invalid.

You can't render anything if you are not triggering a digest. So in this case, the system would know that the field is invalid but it couldn't do anything about it.

This is why I think this PR is flawed.

@shahata
Copy link
Contributor Author

shahata commented May 16, 2014

@IgorMinar - I must be completely missing what you meant to say. A digest always occurs after validation in the current implementation.

Here is a working example of my current implementation: http://plnkr.co/edit/iQzU78XgWP42cfGnGAtq?p=preview As you can see, this behaves as I intended - the validation errors are displayed, but the model is not updated.

Here is how it works without validateOn: http://plnkr.co/edit/cve42XuNC0ykuw8hz81S?p=preview As you can see this is not so comfortable for the user since he can see the validation error only when the model is updated (on blur/submit)

@IgorMinar
Copy link
Contributor

@shahata I see what you mean. ignore my comment :-)

let me take a better look

Add option to set different triggers for validation than the triggers that actually update the model. A new method `$$validateViewValue` was extracted from `$commitViewValue` which can be called when a `validateOn` trigger occurs. This method sets the control as dirty and runs all `$parsers`, but doesn't actually change the model. The idea is that many times people want to pend or debounce the updates to the model in order to prevent a lot of invocations of watchers or just simply to update their model only when a form is submitted, but they would still like their users to get feedback immediately when the view is dirty or invalid.

BREAKING CHANGE:

This commit introduces the option to run `$parsers` without setting the `$modelValue` with the result.

Closes #7016
@petebacondarwin
Copy link
Contributor

This is not a high priority feature so we are going to pop it in the icebox for a bit and revisit it if people start to show an interest.

@sryzycki
Copy link

sryzycki commented Jun 6, 2017

+1

@shahata shahata closed this by deleting the head repository Jun 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add validateOn to ng-model-options to make the $parsers run even when updates are pending
7 participants