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

minDate and maxDate do not work as expected when specify a custom format. #347

Open
ubiyf opened this issue Oct 19, 2015 · 5 comments
Open

Comments

@ubiyf
Copy link

ubiyf commented Oct 19, 2015

In the version 2.4.5 line 1121 and 1125, there is a regular expression check:
/^+-$/.test(options.minDate)
If user specify a custom date format, eg: 'Y-m-d', it will not be matched, so it doesn't work as expected.
It works only with 'Y/m/d' format.

@ghost
Copy link

ghost commented Dec 14, 2015

+1
Having the same problem.

Although I get the feeling the owner doesn't look at the issues that often.

@lure
Copy link

lure commented Mar 4, 2016

This is the answer. All possible format options MUST be specified. I am using date only here, so I have to provide both format and formatDate.

  jQuery(function() {
        var fmt = 'DD.MM.YYYY';
        Date.parseDate = function (input, format) {
            return moment(input, format).toDate();
        };
        Date.prototype.dateFormat = function (format) {
            return moment(this).format(format);
        };

        $.datetimepicker.setLocale("en");
        jQuery('#last-login-from').datetimepicker({
            format: fmt,
            formatDate: fmt,
            validateOnBlur: true,
            allowBlank: true,
            closeOnDateSelect: true,
            datepicker: true,
            timepicker: false,
            onShow: function (ct) {
                var endR = jQuery('#last-login-to').val();
                this.setOptions({
                    maxDate: endR ? endR : false
                })
            }
        });
        jQuery('#last-login-to').datetimepicker({
            format: fmt,
            formatDate: fmt,
            validateOnBlur: true,
            allowBlank: true,
            closeOnDateSelect: true,
            datepicker: true,
            timepicker: false,
            onShow: function (ct) {
                var stR = jQuery('#last-login-from').val();
                alert(stR);
                this.setOptions({
                    minDate: stR ? stR : false
                })
            }
        });
    });

@oreynaldocl
Copy link

+1, I @lure I tried with your example but doesn't work.

@lure
Copy link

lure commented Mar 18, 2016

@ilacyero try add every existing formats to options. May be you use mins/ hours or forget to initialize the proper library. It works for me everywhere.
Not sure if matter, but I use momentum.

@suhaotian
Copy link

same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants