0

I need to add a date input field to my contact site, so that users can select a date when we can call them back. I filled the attribute min with the date of today, to prohibit the user from selecting a date from the past.

But if I try to submit I get "Please enter a value greater than or equal to NaN."

enter image description here

I figured out that this is a bug in the old jquery version which magento 2 is using. They are still using jQuery 1 even when there is already jQuery 3.

What is the best way to replace the jQuery version for the contact site?

1 Answer 1

1

use minDate in your jquery

 <input type="text" name="datepicker" id="datepicker" value="" class="datepicker">

 <script> 
 require(["jquery", "mage/calendar"], function($){
        $("#datepicker").datepicker({
             dateFormat:'mm/dd/yy',
             changeMonth: true,
             changeYear: true,
             yearRange: '2010:2025',
             showMonthAfterYear: false,
              minDate: new Date(),

        }) 
 }); 
</script>

if you are using ui-component then use below code

You can set this field in your ui-component

<field name="date">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">string</item>
                <item name="label" xsi:type="string" translate="true">Date</item>
                <item name="formElement" xsi:type="string">date</item>
                <item name="source" xsi:type="string">page</item>
                <item name="sortOrder" xsi:type="number">1</item>
                <item name="dataScope" xsi:type="string">date</item>
                <item name="options" xsi:type="array">
                    <item name="dateFormat" xsi:type="string">yyyy-MM-dd</item>
                    <item name="minDate" xsi:type="string">new Date()+ 1</item>
                </item>
            </item>
        </argument>
</field>
2
  • Works like a charm, thanks!! :)
    – Black
    Commented May 26, 2021 at 8:25
  • 1
    happy to hear it helps you :) Commented May 26, 2021 at 8:33

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.