Magento – Magento 2: Disable past dates for the Datepicker built via ui-component

datepickerform-validationmagento2uicomponent

I am trying to add a validation to the datepicker so that users won't be able to select past dates. The datepicker is built via ui-component and the code snippet is as follows:

enter image description here

I have checked this link where in they have said to add the javascript in the template file but in our case we don't have any template file.
My case is similar to this post but not getting where to put the javascript.

Any help would be greatly appreciated. Thanks.

Best Answer

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>
Related Topic