-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngModelOptions): support submit trigger #7094
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! |
I thought it would be better to broadcast the submit event on the scope instead of letting each input listen on the form's submit itself. This is much more elegant in my opinion since you don't need to pass the form's element to the input directives. (which is very patchy, not to mention nested forms which will require particular ugly patching) @petebacondarwin @lrlopez what do you think about this? Should I also document the new |
SGTM. I also find convenient to have both the event and the new feature documented. As you stated before, an input control doesn't have a |
* events using an space delimited list. There is a special event called `default` that | ||
* events using an space delimited list. You can also ask to update on `submit`, but make sure | ||
* you handle the submit using `ngSubmit` and not `ngClick` on the submit button in order to | ||
* have the updated model value on your scope. There is a special event called `default` that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should say:
updateOn
: string a space separated list of events; any of which should cause the model to be updated.
There are two "special" events:default
: the standard built-in update event for this input (e.g.change
orinput
).submit
: triggered when an enclosing form is submitted via thesubmit
event. Note thatngClick
events will occur before the model is updated. UsengSubmit
to have access to the updated model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not catch a click
on an input
of type submit
?
Sorry I misread the doc
This is failing e2e tests locally for me:
This looks like the failures we had before due to timing issues... @shahata - did you branch from an old version? |
Or maybe it is me! I'll push to CI and see. |
OK, so Travis and Jenkins are happy with this. Must be something wrong on my end. |
OK, builds now for me locally too. @caitp raised a concern on Gitter, which I think would be dealt with by fleshing out the reasoning behind this change in more detail in the docs, in |
@petebacondarwin I've updated the commit so that update on submit will be the default. (currently there is no way to disable it, but it can be done very easily if we find a reason to do it) Also:
Do you think we should add documentation for this elsewhere? In my opinion the right place to document this is only |
@@ -381,19 +381,21 @@ var formDirectiveFactory = function(isNgForm) { | |||
// IE 9 is not affected because it doesn't fire a submit event and try to do a full | |||
// page reload if the form was destroyed by submission of the form via a click handler | |||
// on a button in the form. Looks like an IE9 specific bug. | |||
var preventDefaultListener = function(event) { | |||
var handleFormSubmission = function(event) { | |||
scope.$broadcast('$flushPendingInput', event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we run this using scope.$evalAsync
? This will guarantee that the handler is called from within a $digest cycle.
We should then expect anyone else who is manually triggering this event to ensure that they are inside a $digest cycle themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why scope.$evalAsync
and not scope.$apply
? I'm afraid that if we use scope.$evalAsync
the event will be handled too late (after ngSubmit
is invoked)
PR updated according to @petebacondarwin comments |
I don't like some things about this PR, mainly all the tweaking with |
I will take a look next week. On 15 April 2014 09:43, Shahar Talmi notifications@github.com wrote:
|
BTW, I have a different PR - #7116 which solves the same issue in a different way and I really prefer instead of this one. |
Closing in favor of #7116 |
Fixes #7017