Markoo08
Markoo08

Reputation: 57

How to validate user inputs in angular formly datepicker?

im using angular-formly on my project. we are allow user to pick date from DP (max:today min:today - 100 years) but user can also edit date in input field. So my question is how to allow user edit date only in range (from today yo today -100 years)

Upvotes: 3

Views: 1691

Answers (1)

Kevin Hernandez
Kevin Hernandez

Reputation: 525

I found the angular-formly UI Datepicker example. Is this what you mean by "DP"?

http://angular-formly.com/#/example/integrations/ui-datepicker

If you're having the user edit the date text as well, then I would suggest having you use an Angular filter as well as date text validation. Here's a really good example for what you need:

https://docs.angularjs.org/api/ng/input/input%5Bdate%5D

If you want your dates to be now - 100 years, set the min to:

<input type="date"
   min="{{myMin}}">

where your controller would have a variable setting the min date

$scope.myMin = new Date().setFullYear(new Date().getFullYear() - 100);

It's untested but you may have to do some "toString" function.

Upvotes: 1

Related Questions