1

In Magento 2 how to restrict previous dates in datepicker ,in detail page customizable options,

Please help me out on this .

1
  • Please show your code.
    – Msquare
    Feb 27, 2021 at 5:08

2 Answers 2

1

In your script add the following

$customId = <?php echo $product->getCustomId();?>
<script>
    require([
        'jquery',
        'mage/calendar'
     ], function($, calendar) {
      $('#<?php echo $customId;?>').calendar({
            dateFormat: 'dd/M/Y',
            changeMonth: true,
            changeYear: true,
            yearRange: '2000:2050',
            minDate: new Date(),
       });
   });
</script>
4
  • HI thanks for comment but in prodcut detail page custom options id is dynamic its keep on chnaging so what i need to do please help me Jul 12, 2019 at 7:25
  • where did you write this script? Is it in phtml?
    – aravind
    Jul 12, 2019 at 7:32
  • yes , iam trying in items.phtml(in magento-catalog) or footer.phtml Jul 12, 2019 at 7:41
  • I have updated my answer
    – aravind
    Jul 12, 2019 at 8:39
0

If you are using Magento calendar library or jQuery date picker library then use below method

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

    $('#example').datepicker({
                        dateFormat: "yy-mm-dd",
                        timeFormat: "H:m:s",
                        changeMonth: true,
                        changeYear: true,
                        numberOfMonths: 1,
                        showsTime: true,
                        minDate: new Date()
                    });
});

In this, the minDate is the Date before which you want to restrict.

2
  • HI thanks for comment but in prodcut detail page custom options id is dynamic its keep on chnaging so what i need to do please help me Jul 12, 2019 at 7:25
  • if the custom option's ID follows a pattern then use $('[id*="option_pattern"]') or use class instead of the Id Jul 13, 2019 at 10:26

Your Answer

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

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