Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datepicker: Input-field does not take locale into account #3206

Closed
leomayer opened this issue Dec 6, 2017 · 1 comment
Closed

Datepicker: Input-field does not take locale into account #3206

leomayer opened this issue Dec 6, 2017 · 1 comment

Comments

@leomayer
Copy link

leomayer commented Dec 6, 2017

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);
@valorkin
Copy link
Member

valorkin commented Dec 7, 2017

Error check of the input - sure you can do any custom validation on input
Manual input parse is known and should be published next, there are similar issue to this one

@valorkin valorkin added this to the v2.0.0-rc.2 milestone Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants