Matt,
Thank you! This works splendidly. One last question, though. How do I bind
this new form to a model?
My previous view was just a single input, bound like this:
<div ng-repeat="person in persons">
<strong>{{person.name}}</strong>
<input type="text" ng-model="person.birthdate ">
</div>
I have replaced the above input as per your suggestion, and that displays
nicely, including the validation, but I don't know how to wire up the
birthdate in the new input boxes to the old birthdate property, so I can
use it throughout the rest of the app.
Thanks again for your help!
Op zondag 12 januari 2014 06:38:02 UTC+1 schreef Matt Bailey:
>
> Hey there,
>
> Here's an example of how you might go about validating a couple fields
> together: http://jsfiddle.net/DFBWK/1/
>
> Basically, you run the validateDate function every time any of the fields
> change and the "birthdate" validation key gets set. This triggers the
> entire form being valid or invalid. You can probably take it from here to
> do whatever you need with it. You can probably set this up several
> different ways, but this is just one way that works.
>
> -Matt
>
> On Friday, January 10, 2014 6:53:20 AM UTC-8, [email protected] wrote:
>>
>> Hi,
>>
>> I am trying to write a custom validator to validate a birthdate which the
>> user enters using three input fields, e.g.
>>
>> <input type="text" name="day" ng-model="person.day" />
>> <input type="text" name="month" ng-model="person.month" />
>> <input type="text" name="year" ng-model="person.year" />
>>
>> Together, they have to make up for a valid date object, otherwise they
>> should invalidate the form and display a warning to the user.
>>
>> How should I go about this using directives? I'm comfortable validating a
>> single field, but I am unsure how to combine dependent fields such as
>> these. As I will be using this more often, I'd like to prevent building a
>> function directly in the controller. I can't wrap my head around the
>> documentation regarding this. Any help will be appreciated. Thanks!
>>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.