Closed
Description
Setting the datepicker with locale to e.g. de
the date format changes from MM/DD/YY
to DD/MM/YY
.
I can type the date via the input field manually, e.g. 6th Dec 17 in 'de' ==> 06/12/17
. When I change the input manually to 07/12/17
I get as a result in the calendar 12th Jul 17 - because date and months are switched.
Additionally (not directly related but nevertheless) I wanna ask if its not easy possible to add an Error check of the input - and assign it to a specific class (when the input fails to be converted to an appropriate date)
Since I know the input is a pain in the a** and the details get someone clz to nut I can provide some sample code as I did the conversion & checks (and validation of the input) - just as an inspiration...
const val = this.internalDateString.trim();
if (val) {
let inValid = !moment(val, this.dateFormat, true).isValid();
if (!inValid) {
const test = moment(val, this.dateFormat, true).toDate();
if (this.minDate && test < this.minDate) {
inValid = true;
} else if (this.maxDate && test > this.maxDate) {
inValid = true;
}
if (!inValid) {
// users input is a valid date (according to the format) ==> proceed....
this.internalDate = test;
}
}
this.isInValid = inValid; // used for hte bootstrap-class [has-error]
// update the model
this.onChange(this.internalDate);