Meteor-Community-Packages / meteor-autoform-bs-datepicker

Custom "bootstrap-datepicker" input type for AutoForm
MIT License
25 stars 32 forks source link

Date format from "dd/mm/yyyy" to "mm/dd/yyyy" on form save #17

Closed tobiaghiraldini closed 7 years ago

tobiaghiraldini commented 9 years ago

I am using aldeed:simple-schema and aldeed:autoform with aldeed:autoform-bs-datepicker. Setting the picker's format in the date field schema definition I am facing a strange behaviour when saving. The picker correctly fills the date in the field with the correct format ("dd/mm/yyyy)", but once I save the form, it switches the date to the other ("mm/dd/yyyy"). This makes the date to be saved in the wrong format. Here is my schema, and form field:

Schema

birthDate: {
    type: Date,
    autoform: {
        afFieldInput: {
            type: "bootstrap-datepicker",
            datePickerOptions:
                {
                    format: "dd/mm/yyyy",
                    language: "it-IT"
                }
        }
    },
    label: function () {
        return TAPi18n.__("Birth Date");
    },
    optional: true
},

Form

{{> afQuickField name="birthDate" buttonClasses="fa fa-calendar" }}

Is there any other way to specify the date input format? Shouldn't this be enough for field format specifications?

machwatt commented 9 years ago

Getting the same behaviour, after switching the datepicker format via datePickerOptions.format

JcBernack commented 8 years ago

I got the same problem using the german locale. I just use language: "de" and it correctly displays the date as dd.mm.yyyy, but querying the datepickers value using $("#id").datepicker("getUTCDate") causes the datepicker to fall back to the american locale and it returns a wrong date where month and day are swapped.

I tried to build a minimal repro but was not successful so far.

JcBernack commented 8 years ago

I found a clue on what is going on here:

Short version: Remove the buttonClasses="fa fa-calendar" and it should work.

Long version: When using the buttonClasses attribute the input element gets wrapped in a div and somehow the datepickers data attributes end up on the container div instead of the actual input. This causes the datepicker to miss the supplied options when calling getUTCDate and therefore interpreting the date with the default format mm/dd/yyyy.

dw72 commented 8 years ago

Any workaround to have both correct dates and "calendar button"?

tobiaghiraldini commented 8 years ago

As a workaround you can configure your field with your desired format in the schema and provide with a calendar field plugin directly in the html, using fontawesome for example. Following this route, you cannot use the quickfield template, but you’ll need to provide your own. You can contact me in case you’ll need more info.

Il giorno 20/gen/2016, alle ore 13:52, dw72 notifications@github.com ha scritto:

Any workaround to have both correct dates and "calendar button"?

— Reply to this email directly or view it on GitHub https://github.com/aldeed/meteor-autoform-bs-datepicker/issues/17#issuecomment-173195452.

aldeed commented 7 years ago

Closing old issues. Can be reopened if it's still an issue in the latest release.