1

Can anyone help me in creating a Angular-js Directive that can handle three field date,

I need a directive for the solution specified in the below link,

http://plnkr.co/edit/lHffXV7xEda0xYorucMe?p=preview

I tried out a couple of solutions and was not rendering properly.

Any plunker illustration would also help. A plunker link is specified below,

http://plnkr.co/edit/lHffXV7xEda0xYorucMe?p=preview

6
  • If all that you need is html template to be stored as different file so here is directive:plnkr.co/edit/sia1HAGB8aIytPVD7Juy?p=preview Commented Jan 2, 2014 at 6:35
  • Many Thanks - How will the ng-model binding with the back end JSON Obejct will work in this scenario. Commented Jan 2, 2014 at 6:38
  • I require to reuse the same date in other places, Is this a standard to use it in this way ? Commented Jan 2, 2014 at 6:48
  • Can any one help, I need to pass ng-modiel for three date boxes. Commented Jan 2, 2014 at 7:38
  • I didnt quite understand, what the problem you trying to solve: in your example you already have three inputs each attached to some ng-model, what you want to be different? Commented Jan 2, 2014 at 9:00

1 Answer 1

1

See ngModelController for an example how to implement a custom directive with ng-model support. I have created a simple implementation based on this example, you can see demo here.

My current implementation has one drawback - it does not handle invalid dates correctly. To fix this you could either make sure that user cannot enter invalid date or add validation support to the directive via $formatters and $parsers of ngModelController. I guess the latter would not be difficult, if I have time I'll try to do that later.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the input, this is the exact this I needed, could you please help me out, with the validators as well. Thanks in advance.
and also JQuery shouldnt be used.
The soultion is excellent, here another query is mhow will I format the DATE TO DD-MM-yyyy to ng-model binding object..?
I have added validation support and some tests: github.com/romario333/datedirective jQuery is not needed for this directive, the only required dependency is Angular.js. As to your question about formatting, what do you mean? You don't need to format the value you bind via ng-model, it's always of Date type.
My requirement is when I specify an ngModel="someVariable", the data binded should be in the format yyyy-MM-dd,
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.