Not sure what are you are trying to achieve here but I would assume
that you want to do some custom validation of the value entered in the
input field. If so I can see at least 2 ways of approaching this:
1) Using directives; see the "Custom validation" section in
http://docs-next.angularjs.org/guide/dev_guide.forms; My understanding
is that this is "the angular way".
2) Let the binding to the model occur, $watch this model value and do
custom logic in there;
Please also not that you've got an input type "number"
(http://docs-next.angularjs.org/api/angular.module.ng.$compileProvider.directive.input.number)
where you've got several built-in validation options (required, min,
max). I've noticed that you are using type="text" in your example so
not benefiting from the angular validation.
Anyway, would be great if you could elaborate on your scenario,
preferably using jsFiddle. You can us this one
http://jsfiddle.net/IgorMinar/CHVbb/364/ as a starting point.
Hope this helps,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/zxgZ2iE92sIJ.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.
On Thu, Apr 12, 2012 at 2:54 PM, <mario...@googlemail.com> wrote:
> So is it possible to get the directive called just then when I loose focus?
> I don't want to get the directive called after the the first entry in the
> field! Just after I inserted e.g '2,11'...
OK, I didn't realize that you want to validate just after completing
all the input. There was a recent change when ngModelInstant was added
back and forth but ultimately was removed in rc4
(https://github.com/angular/angular.js/blob/master/CHANGELOG.md#1.0.0rc4)
as several people were rising concerns about it (search the mailing
list history for model instant to see the history).
Honestly, with the ngModelInstant removed (and binding behaving like
ngModelInstant by default) I'm not sure what would be the proper way
of triggering the validation only after control is loosing the
focus...
Cheers,
Pawel
On Thu, Apr 12, 2012 at 2:50 PM, Freewind <nowi...@gmail.com> wrote:
> I've the same question, and I made a simple
> demo: http://jsfiddle.net/Freewind/zGm4p/
Corrected a bit the fiddle (change type of the input to "email" and
there was a bug in the alert): http://jsfiddle.net/zGm4p/2/
> What I want is to validate the email only if I lost focus on the input, e.g.
> press tab key, or click on the blank page.
Yep, I see, no clue how to do it properly in angular :-( But would
love to know the answer :-)
Cheers,
Pawel
This is becoming a recurring theme. I wonder if model changes are actually the best place for validation? Given the wide range of requirements perhaps an event based mechanism would be more flexible and perform faster.
My idea would be that every input directive would trigger events such as select, change or blur. You then set up the form to trigger validation based on these events asking all the directives whether the are valid. Reasonable defaults should mean that most cases would work without unwanted declarations but that social cases can be configured on a form by form basis.
Pete
...from my mobile.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
We do validation on model update, because you want to have your the valid. (invalid view does not update model).You can override input directive, to use "blur" event:
V.
On Thu, Apr 12, 2012 at 7:00 AM, Peter Bacon Darwin <pe...@bacondarwin.com> wrote:
This is becoming a recurring theme. I wonder if model changes are actually the best place for validation? Given the wide range of requirements perhaps an event based mechanism would be more flexible and perform faster.
My idea would be that every input directive would trigger events such as select, change or blur. You then set up the form to trigger validation based on these events asking all the directives whether the are valid. Reasonable defaults should mean that most cases would work without unwanted declarations but that social cases can be configured on a form by form basis.
Pete...from my mobile.
On Apr 12, 2012 2:04 PM, "Pawel Kozlowski" <pkozlowski.opensource@gmail.com> wrote:
hi!
On Thu, Apr 12, 2012 at 2:54 PM, <mario...@googlemail.com> wrote:
> So is it possible to get the directive called just then when I loose focus?
> I don't want to get the directive called after the the first entry in the
> field! Just after I inserted e.g '2,11'...
OK, I didn't realize that you want to validate just after completing
all the input. There was a recent change when ngModelInstant was added
back and forth but ultimately was removed in rc4
(https://github.com/angular/angular.js/blob/master/CHANGELOG.md#1.0.0rc4)
as several people were rising concerns about it (search the mailing
list history for model instant to see the history).
Honestly, with the ngModelInstant removed (and binding behaving like
ngModelInstant by default) I'm not sure what would be the proper way
of triggering the validation only after control is loosing the
focus...
Cheers,
Pawel
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
We do validation on model update, because you want to have your the valid. (invalid view does not update model).You can override input directive, to use "blur" event:
V.
On Thu, Apr 12, 2012 at 7:00 AM, Peter Bacon Darwin <pe...@bacondarwin.com> wrote:
This is becoming a recurring theme. I wonder if model changes are actually the best place for validation? Given the wide range of requirements perhaps an event based mechanism would be more flexible and perform faster.
My idea would be that every input directive would trigger events such as select, change or blur. You then set up the form to trigger validation based on these events asking all the directives whether the are valid. Reasonable defaults should mean that most cases would work without unwanted declarations but that social cases can be configured on a form by form basis.
Pete...from my mobile.
On Apr 12, 2012 2:04 PM, "Pawel Kozlowski" <pkozlowski.opensource@gmail.com> wrote:
hi!
On Thu, Apr 12, 2012 at 2:54 PM, <mario...@googlemail.com> wrote:
> So is it possible to get the directive called just then when I loose focus?
> I don't want to get the directive called after the the first entry in the
> field! Just after I inserted e.g '2,11'...
OK, I didn't realize that you want to validate just after completing
all the input. There was a recent change when ngModelInstant was added
back and forth but ultimately was removed in rc4
(https://github.com/angular/angular.js/blob/master/CHANGELOG.md#1.0.0rc4)
as several people were rising concerns about it (search the mailing
list history for model instant to see the history).
Honestly, with the ngModelInstant removed (and binding behaving like
ngModelInstant by default) I'm not sure what would be the proper way
of triggering the validation only after control is loosing the
focus...
Cheers,
Pawel
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.
That’s not the reason. It doesn’t matter what you name the controller parameter in the link function, you could name it theControllerForTheDirectiveNgModel
and it would still work. The problem is that the order that priority is applied has changed causing Vojta’s directive to execute before the built-in input directive. You need to make sure the new directive has larger priority so that it will execute after the built-in. Since built-in directive has a priority of 100, adding a priority of 101 will make sure it executes after and make everything work as expected.