0

In my customer edit form, for telephone phone, required field validation is not working when I leave the telephone field blank. The required validation works for every field except for the telephone field.

When I save the form without telephone field, after the backend call it gives me a notification message " telephone" is required. Enter and try again.

enter image description here

This is code for password field in my form

<div class="field telephone required">
<label for="telephone" class="label">
    <span>
        Phone Number 
    </span>
</label>
<div class="control">
    <input type="text" name="telephone" id="telephone" value="" title="Phone Number" class="input-text " sr-only="INPUT" for="INPUT" aria-required="true">
</div>

I even checked eav_attribute table. It has is_required=1 for attribute_code='telephone'

I don't want notification, it should be like other fields inline validation.

5
  • 5
    try adding the required-entry class to the input.
    – Marius
    Mar 14, 2019 at 6:44
  • change it to simple require required="true"
    – fmsthird
    Mar 14, 2019 at 6:46
  • @Marius Thanks, looks like the vendor code was faulty, they were adding validation class by using fax $_validationClass = $block->escapeHtmlAttr( $this->helper('Magento\Customer\Helper\Address') ->getAttributeValidationClass('fax') );
    – summu
    Mar 14, 2019 at 6:56
  • Just replaced fax with telephone and it worked in my overridden file
    – summu
    Mar 14, 2019 at 6:56
  • 1
    @summu Put your findings in an answer and mark it as accepted.
    – Marius
    Mar 14, 2019 at 6:57

2 Answers 2

1

You just need to add required-entry class in the input field as:

<input type="text" name="telephone" id="telephone" value="" title="Phone Number" class="input-text required-entry" sr-only="INPUT" for="INPUT" aria-required="true">

Its working fine for me.

0

looks like the vendor code was faulty, They were adding _validationClass by using getAttributeValidationClass of fax

vendor/Magento/module-customer/view/frontend/templates/widget/telephone.phtml

<div class="control">
    <?php
        $_validationClass = $block->escapeHtmlAttr(
            $this->helper('Magento\Customer\Helper\Address')
                 ->getAttributeValidationClass('fax')
        );
    ?>
    <input type="text"
           name="telephone"
           id="telephone"
           value="<?= $block->escapeHtmlAttr($block->getTelephone()) ?>"
           title="<?= $block->escapeHtmlAttr(__('Phone Number')) ?>"
           class="input-text <?= $_validationClass ?: '' ?>"
    >
</div>

As required-entry class is missing so, Just change it to ->getAttributeValidationClass('fax') to ->getAttributeValidationClass('telephone') and it will work.

1
  • I clearly mentioned, that is_required is 1 for attribute_code='telephone' and you just reiterate same thing using admin panel, solution was i was missing required-entry class,
    – summu
    Mar 14, 2019 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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