1

I have created one custom form and implemented magento validation. Magento validation works for all fields but message of one field is not displaying. I have added datepicker in this field.

Below is the code of my field:

<div class="field field-name-reward_date required">
<label class="label required" for="reward_date"><span>Reward Distribution Date</span></label>
<div class="control date">
    <input type="text" name="reward_date" class="input-text _has-datepicker mage-error" data-validate="{'required':true, 'validate-reward-date':true}" id="dp1544438747646" aria-required="true" autocomplete="off" aria-invalid="true">
    <span class="calender-icon glyphicon glyphicon-calendar"></span>
</div>

It shows red border when field is not valid, but it not show the message. enter image description here

Please let me know if anyone can help.

2
  • Hi Gaurav facing the same issue do you got any solution for this Commented Jan 26, 2019 at 15:07
  • It was because of datetimepicker which I was using here. So I replaced it with datetimerangepicker with single datepicker. Commented Jan 28, 2019 at 9:11

1 Answer 1

1

add billow JS script to your form

<script>
    require([
        'jquery',
        'mage/mage',
        'mage/validation'
    ], function($){

            var dataForm = $('#form-id');
            dataForm.mage('validation', {
                errorPlacement: function(error, element) {
                    error.insertAfter(element);
                }
            });

});
</script>

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.