0

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 at 5:08
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 – Chala Chalapathi Jul 12 '19 at 7:25
  • if the custom option's ID follows a pattern then use $('[id*="option_pattern"]') or use class instead of the Id – Bhupendra Bisht Jul 13 '19 at 10:26
0

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 – Chala Chalapathi Jul 12 '19 at 7:25
  • where did you write this script? Is it in phtml? – aravind Jul 12 '19 at 7:32
  • yes , iam trying in items.phtml(in magento-catalog) or footer.phtml – Chala Chalapathi Jul 12 '19 at 7:41
  • I have updated my answer – aravind Jul 12 '19 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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