Repository navigation
Conversation
|
Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
|
What about setting $dirty etc. when there's a viewValue, but the model hasn't been set? Is this supported or is everything delayed? |
There was a problem hiding this comment.
Can we have a simpler title here? Perhaps even split out the two different features ("custom triggers" and "debounced updates") into two sections?
|
@Narretz, everything is delayed until the model is set. |
There was a problem hiding this comment.
We should probably make it clear that no update of any kind occurs till the debounce resolved. I.E. No parsers, nor validators are run and $pristine is not affected.
By default, any change on the content will trigger an immediate model update
and form validation. This PR implements a new directive `ng-model-options`
that allow you to override this default behavior in several ways.
You should specify an object with the different parameters.
For example, it allows to trigger an update only when a particular event or
list of events is received by the input using the `updateOn` key. Should you
need multiple events, just assign an array to it.
I.e. `ng-model-options="{ updateOn: 'blur' }"` will update and validate only
after the control loses focus.
If you want to keep the default behavior and just add new events that may
trigger the model update and validation, add "default" as one of the specified
events.
I.e. `ng-model-options="{ updateOn: ['default','submit'] }"`
Also, with the `debounce` option, `ng-model-options` will allow deferring the
actual model update until a timer expires. The timer will be reset each time
an event is triggered.
I.e. `ng-model-options="{ debounce: 500 }" for 500ms after the latest event.
Custom timeouts for each event can be set for each event if you use an object
in `debounce`. This can be useful to force immediate updates on some specific
circumstances (like blur events).
I.e. `ng-model-options="{ updateOn: ['default', 'blur'], debounce: { default: 500, blur: 0} }"`
You can use the directive in any tag so its contents became the default settings
for any child control, although they can be overridden.
Closes angular#1285, angular#2129
|
Thanks for the suggestions @caitp and @IgorMinar. They make the PR simpler. I've amended the commit. |
There was a problem hiding this comment.
do we have to support list of events as an array? if we said that only space delimited strings are allowed ('blur click') then we wouldn't need forEach when registering listeners jquery/jqlite on support space delimited list of events and we could generally simplify quite a bit of code. (var events = options.$updateOn || options.$updateOnDefault; element.on(events, function() { ... });)
There was a problem hiding this comment.
or even
element.on(options.$updateOn || options.$updateOnDefault, function() { ... });|
ok, I know that I left a lot of comments. @lrlopez, I don't mean to discourage you. This is a really good change, it just needs a bit more polish and then we can ship it. Good work! (also @petebacondarwin and @auser) |
By default, any change on the content will trigger an immediate model update and form validation. This PR implements a new directive
ng-model-optionsthat allow you to override this default behavior in several ways.You should specify an object with the different parameters.
For example, it allows to trigger an update only when a particular event or list of events is received by the input using the
updateOnkey. Should you need multiple events, just use a space delimited string.I.e.
ng-model-options="{ updateOn: 'blur' }"will update and validate only after the control loses focus.If you want to keep the default behavior and just add new events that may trigger the model update and validation, add "default" as one of the specified events.
I.e.
ng-model-options="{ updateOn: 'default submit' }"Also, with the
debounceoption,ng-model-optionswill allow deferring the actual model update until a timer expires. The timer will be reset each time an event is triggered.I.e. `ng-model-options="{ debounce: 500 }" for 500ms after the latest event.
Custom timeouts for each event can be set for each event if you use an object in
debounce. This can be useful to force immediate updates on some specific circumstances (like blur events).I.e.
ng-model-options="{ updateOn: 'default blur', debounce: { default: 500, blur: 0} }"You can use the directive in any tag so its contents became the default settings for any child control, although they can be overridden.
Closes #1285, #2129