1

I have successfully added calender in my custom form by using below code.

<script>
                require([
                    "jquery",
                    "mage/calendar"
                    ], function($){

                        $("#My_ID").calendar({
                            showsTime: false,   
                            hideIfNoPrevNext: true,
                            buttonText:"<?php echo __('Select Date') ?>",
                //dateFormat: "yy-mm-dd"
            }); 
                    });             
            </script>

But, How can I disable previous days in default magento2 calendar?

Any help will be appreciated.

Thanks.

1
  • Can you show me step by step to add this script to from ?
    – MrTo-Kane
    Commented Mar 14, 2016 at 7:14

1 Answer 1

10

You can set your minDate or maxDate in order to limit your calendar.

<script>
    require([
        "jquery",
        "mage/calendar"
    ], function ($) {

        $("#My_ID").calendar({
            showsTime: false,
            hideIfNoPrevNext: true,
            buttonText: "<?php echo __('Select Date') ?>",
            minDate: new Date(),
            dateFormat: 'yy-mm-dd'
        });
    });
</script>
9
  • You are always welcome brother Commented Mar 22, 2016 at 8:55
  • @akshay how to change date format and disable previous date Commented Mar 22, 2016 at 12:03
  • @akshay I am usign this for datepicker oyenetwork.com/articles/… Commented Mar 22, 2016 at 12:22
  • @pradeep: Magento calendar is the extended version of jQuery calendar , So you can use the properties available in jQuery calendar. Please follow below reference URL : jqueryui.com/datepicker/#date-formats Commented Mar 22, 2016 at 12:26
  • @akshay Yes, I know but in which file need to add code for change format Commented Mar 22, 2016 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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