0

I have created a custom shipping address field which is dropdown select and shows on checkout page. While creating attribute I wrote their required => true

but it is not working. I am able to save address without input in that field. Please guide me.

InstallData.php

$customerSetup->addAttribute('customer_address', 'industry_type', [
            'label' => 'Industry Type',
            'input' => 'select',
            'type' => 'varchar',
            'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Table',
            'required' => true,
            'position' => 333,
            'visible' => true,
            'system' => false,
            'is_used_in_grid' => false,
            'is_visible_in_grid' => false,
            'is_filterable_in_grid' => false,
            'is_searchable_in_grid' => false,
            'backend' => '',
            'option' =>
            array (
                'values' =>
                    array (
                        0 => 'Federal Government',
                        1 => 'State Government',
                        2 => 'Local Government',
                        3 => 'K through 12',
                        4 => 'Higher Education',
                        5 => 'Non Profit',
                        6 => 'Government Health Ca',
                        7 => 'Private Hospital',
                        8 => 'Doctor\'s Office',
                        9 => 'Teaching Hospital',
                        10 => 'None',
                        11 => 'Commercial',
                    ),
            ),
        ]);
0

Please refer this Magento Dev Docs link - https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html

You would need to add it like this -

'validation' => [
   'required-entry' => true
],
4
  • please check my updated question. I am only using this code in installdata.
    – temper
    Dec 17 '19 at 7:46
  • Just being a bit catchy, Could you try removing this node 'required' and see if the db table eav_attribute gets is_required 1? The default value for required is 1(bool true) Dec 17 '19 at 7:57
  • ok I will try and let you know if it works.
    – temper
    Dec 17 '19 at 7:58
  • temper how did it go? Dec 18 '19 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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