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.
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();
}
Best Answer
If you want to remove require entry for admin you have replace 1 to 0 in "eav_attribute" on particular "attribut_code"
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)