1

In Magento 1, under your system config .i.e the system xml, you could make a column a required column by doing this:

<required>true</required>

so the entire config could look like this:

  <config>
   <sections>
    <au translate="label" module="auth">
        <groups>
            <aug translate="label" module="auth">
                <fields>
                    <email_input translate="label">
                        <required>true</required>
                        <label>email: </label>
                        <frontend_type>text</frontend_type>
                        <sort_order>1</sort_order>
                    </email_input>
                </fields>
            </aug>
        </groups>
    </au>
</sections>

What is the Magento 2 equivalent?

I tried doing this:

<field id="au" translate="label" required="true"type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="1">
    <label>email:</label>
 </field>

I also tried this:

<field id="au" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="1">
    <label>email:</label>
    <required>true</required>
</field>

But both give errors

4

You can add single validation class in system.xml

<field id="title" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                   <validate>required-entry</validate>
   </field>

Multiple validation classes

<field id="title" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>Title</label>
                    <validate>required-entry validate-digits</validate>
   </field>

Available classes.

'required-entry'                => 'This is a required field.'
'validate-number'               => 'Please enter a valid number in this field.'
'validate-email'                => 'Please enter a valid email address. For example
johndoe@domain.com.'
'validate-date'                 => 'Please enter a valid date.'
'validate-select'               => 'Please select an option.'
'validate-no-html-tags'         => 'HTML tags are not allowed'
'validate-digits'               => 'Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.'
'validate-url'                  => 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)'
'validate-not-negative-number'  => 'Please enter a number 0 or greater in this field.'
'validate-zero-or-greater'      => 'Please enter a number 0 or greater in this field.'
'validate-state'                => 'Please select State/Province.'
'validate-cc-number'            => 'Please enter a valid credit card number.'
'validate-data'                 => 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.'

Reference link

| improve this answer | |

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.