0

I want to remove the mandatory validation for customer fields eg. firstname, lastname (both for frontend and admin).

I tried using UpgradeData to change the value of is_required field to 0 in the eav_attribute table.

This changes the required condition in the customer logged in page as not required for firstname and lastname.

But in the admin panel while adding new customer, the firstname field goes not required, whereas the lastname field remains required.

What can I do to remove the required field in the lastname in admin panel.

Admin Panel With lastname as required

UpgradeData.php

class UpgradeData implements UpgradeDataInterface
{
    public function __construct(
        EavSetup $eavSetupFactory
    )
    {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
        $setup->startSetup();
        if (version_compare($context->getVersion(), '1.0.1', '<')) {
            $this->eavSetupFactory->updateAttribute(1,5,'is_required',0,null);
            $this->eavSetupFactory->updateAttribute(2,23,'is_required',0,null);
        
            $this->eavSetupFactory->updateAttribute(1,7,'is_required',0,null);
        
            $this->eavSetupFactory->updateAttribute(2,25,'is_required',0,null);
         }
         $setup->endSetup();

}

FirstName is_required as 0 in db FirstName is_required as 0

LastName is_required as 0 in db LastName is_required as 0

9
  • share the code which you are try into UpgradeData Oct 8, 2021 at 5:39
  • I have added the code for UpgradeData
    – Jason
    Oct 8, 2021 at 6:45
  • Bhavin, that doesn't work and thats not a solution too.
    – Jason
    Oct 8, 2021 at 7:27
  • Jason, below solution is for admin only, are you try it?? Oct 18, 2021 at 5:32
  • Below solution is working for admin?? Oct 18, 2021 at 5:42

1 Answer 1

1

If you want to remove require entry for admin you have replace 1 to 0 in "eav_attribute" on particular "attribut_code"enter image description here

and after that, you have also to comment or remove

<validation> <rule name="required-entry" xsi:type="boolean">true</rule> </validation>

from: vendor\magento\module-customer\view\base\ui_component\customer_form.xml (override customer_form.xml file in your module) enter image description here

0

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.