3

Using below I added the datepicker. I'm trying to disable the date smaller than what input field specifies but it enables picking any date older than input value.

    <script>
        require([
            "jquery",
            "mage/calendar"
        ], function ($) {
            $(document).ready(function () {
                     //Input format --> 02.11.2017  
                var str = $("#fix_time").val().split(".");
                var toDate = new Date(str[2], str[1] - 1, str[0]);
                $('#fix_time').datepicker('setDate', toDate);

                $('#fix_time').datepicker({
                    prevText: '&#x3c;zurück', prevStatus: '',
                    prevJumpText: '&#x3c;&#x3c;', prevJumpStatus: '',
                    nextText: 'Vor&#x3e;', nextStatus: '',
                    nextJumpText: '&#x3e;&#x3e;', nextJumpStatus: '',
                    monthNames: ['Jan','Feb','Mar','Apr','May','Jun',
                        'Jul','Aug','Sep','Oct','Nov','Dec'],
                    dayNames: ['Sun','Mon','Teu','Wed','Thu','Fri','Sat'],
                    showMonthAfterYear: false,
                    dateFormat:'dd.mm.yy'
                });

});
    });
</script>

Thanks.!

0

1 Answer 1

3

You can restrict the Min date by passing minDate value.

Eg:

var str = $("#fix_time").val().split(".");
var toDate = new Date(str[2], str[1] - 1, str[0]);
$('#fix_time').datepicker('setDate', toDate);

$('#fix_time').datepicker({
    prevText: '&#x3c;zurück', prevStatus: '',
    prevJumpText: '&#x3c;&#x3c;', prevJumpStatus: '',
    nextText: 'Vor&#x3e;', nextStatus: '',
    nextJumpText: '&#x3e;&#x3e;', nextJumpStatus: '',
    monthNames: ['Jan','Feb','Mar','Apr','May','Jun',
        'Jul','Aug','Sep','Oct','Nov','Dec'],
    dayNames: ['Sun','Mon','Teu','Wed','Thu','Fri','Sat'],
    showMonthAfterYear: false,
    dateFormat:'dd.mm.yy',
    minDate: toDate //your input box date value
});
1
  • How to disable past and future date in admin panel in custom form date in magento 2 with UI component. Apr 20, 2017 at 16:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.