Re: [angular.js] Re: How to make email field invalid unless email unique

829 views
Skip to first unread message

Pawel Kozlowski

unread,
Jul 24, 2012, 7:42:03 AM7/24/12
to ang...@googlegroups.com
Rob,

You can inject $http the same way as $location in your directive's
function.This is the magic of dependency injection :-)

Cheers,
Pawel

On Tue, Jul 24, 2012 at 1:32 PM, Rob Hicks <r...@hixfamily.org> wrote:
> Philipp,
>
> Thanks, that helps, although the unshifting the $parsers seems odd.
>
> To invalidate the field though, I would need to get access to the $http
> service from within the directive. I searched but only found getting access
> to $location from within the directive. Is the $http service accessible
> within directives? The server needs to be queried to determine if the email
> address has already been used.
>
> Rob
>
> On Tuesday, July 24, 2012 2:14:14 AM UTC-6, Philipp Burgmer wrote:
>>
>> Hi,
>>
>> For information about custom validation take a look at
>> http://docs.angularjs.org/guide/forms. There's a paragraph "Custom
>> Validation".
>> I think this is what you need ;)
>>
>>
>> Greetings,
>> Philipp
>>
>> Am Montag, 23. Juli 2012 17:51:22 UTC+2 schrieb Rob Hicks:
>>>
>>> Hi,
>>>
>>> App needs to ensure email address is unique.
>>>
>>> See jsfiddle.
>>>
>>> How do I modify the directive to make fail validation for the field?
>>>
>>> Do I need to build a service for the directive?
>>>
>>> Thanks!
>>>
>>> Rob
>
> --
> 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/-/Nx4DNLvBrJoJ.
>
> 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.

Philipp Burgmer

unread,
Jul 24, 2012, 10:44:22 AM7/24/12
to ang...@googlegroups.com
You have defined $http as dependency but you don't take a parameter.
Look at this fiddle: http://jsfiddle.net/RP8dh/20/


Philipp


2012/7/24 Rob Hicks <r...@hixfamily.org>
Hi Pawel,

So what is the magic incantation to inject $http into a directive? Look at my jsfiddle. Even though I did it the way that $location was shown in a previous post, it throws an error.

Thanks,
Rob
> 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 view this discussion on the web visit https://groups.google.com/d/msg/angular/-/ktxXmWAv_LkJ.

Danny Staten

unread,
Jun 27, 2013, 12:46:33 PM6/27/13
to ang...@googlegroups.com
One question.  This is working great, but I would prefer not to fire an http request for every key press.  Where can I find out what I need to do in order for this custom directive's validator to only run when the control has lost focus, or something along those lines?


On Tuesday, July 24, 2012 9:33:21 AM UTC-6, Rob Hicks wrote:
Ah! Thanks.


2012/7/24 Rob Hicks <r...@hixfamily.org>

Alexander Kohout

unread,
Jun 28, 2013, 3:00:27 AM6/28/13
to ang...@googlegroups.com
You have to unbind the change and keydown events, and instead bind an on-blur event listener.

I did it like this: http://jsfiddle.net/uX5ZH/

I use this directive for all input fields I want to be validated on blur instead of on keydown.

Michael Azerhad

unread,
Oct 10, 2013, 11:12:47 PM10/10/13
to ang...@googlegroups.com
Doesn't work when added: unbind('input')

The unbinding line is left to: element.unbind('keydown').unbind('change');

Are you sure about adding "unbind('input')" in this case ?

Thanks :)

Michael

Alexander Kohout

unread,
Oct 11, 2013, 1:00:46 AM10/11/13
to ang...@googlegroups.com
Ehm, don't know where the unbind('input') comes from :D Yeah, that's not so helpful :-)


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/_xO8ePPXAEc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages