How to set timer for an disabled button tp be enabled using js.

Here first of all we need to open a <script> tag and add the folllowing code

<script type="text/x-magento-init">
    {
        "#country": {
            "regionUpdater": {
                "optionalRegionAllowed": <?= /* @noEscape */ $displayAll ? 'true' : 'false' ?>,
                "regionListId": "#region_id",
                "regionInputId": "#region",
                "postcodeId": "#zip",
                "form": "#form-validate",
                "regionJson": {$regionJson},
                "defaultRegion": "{$regionId}",
                "countriesWithOptionalZip": {$countriesWithOptionalZip}
            }
        }
    }
</script>

Then you nee to add another script tag and give the form id which is given for the form in the phtml file
 

<script type="text/x-magento-init">
    {
        ".field.password": {
            "passwordStrengthIndicator": {
                "formSelector": "form.form-create-account"
            }
        },
        "*": {
            "Magento_Customer/js/block-submit-on-send": {
                "formId": "form-validate"
            }
        }
    }
</script>


And now we are writing the if condition and setting the timer if that if condition execute the the enablig action will execute after the specified time.

<script type="text/javascript">
    require([
        "jquery"
    ],function($) {
        $(document).ready(function(){
            $('#form-validate').on('submit', function(e) {
                var errors=0;
                if (!(jQuery('#form-validate').valid()))
                {
                            setTimeout(function(){
                            $('#signup-registration').removeAttr("disabled");
                        }, 1000);
            
                }

                
});
});
});
</script>

Leave a comment

Your email address will not be published. Required fields are marked *