I need add ionic datepicker inside in a ionic form. I have follow this doc for install datepicker but i don’t have any idea how i can use datepicker inside the form and i need some date validation also like normal form input. Assume i only need take a birth day and that filed cannot be edit using strings i mean date format. also that date should not be today day.
I used basic html to create my target page. Here is my code look likes
have you any idea about validation of this date picker? because i need set max year should be -16 from current year, and i need add required validation to this ion-datetime element
you can set min max value like this <ion-datetime displayFormat="MMMM YYYY" min="2016" max="2020-10-31" [(ngModel)]="myDate">
for more detail you can refer this
you don’t need to have native datepicker. you can use the default datepicker and the datepicker do not allow string value for date. If you but max and min value you don’t need additional validation.
Here i have two way data bind variable call year in max="" property that year is calculated by the typescript file and send here the final value.
Those codes are
year = null;
currentTime = null;
in_some_method(){
// paste this code, should be include those are to constructor
this.currentTime = new Date();
this.year = this.currentTime.getFullYear();
this.year = this.year - 16;
}
And i have use Reactive Form in angular so i have set validation like
So this is the completed code which i successfully combined.
Like Mr. @haniniw said you don’t need any extra library. Thank you Mr. @haniniw and also thank you Mr. @mohamedwahshey
However i have some small un solved problem here, when i not validate some form control element then that time give me red color underline indication that fields are not valid, i also have set data picker as required field but that not shows me any red underline error, i see that also happens to ion-select element.