Magento – How to set required Gender field in magento 2

customermagento-enterprisemagento2

I'm working with magento 2. when i want to set required for Gender field in Admin. It required me to config something.
This picture describes my problem

Best Answer

You have to add field with require as bellow.

for example in my custom module the field i have added in

Custom\News\Block\Adminhtml\Items\Edit\Tab\Main.php;

like

$fieldset->addField(
            'news_short_description',
            'editor',
            [
                'name' => 'news_short_description',
                'label' => __('Short Description'),
                'title' => __('Short Description'),
                'class' => 'validate-length maximum-length-100',
                'required' => true
            ]
        );

or as like bellow

 $fieldset->addField(
            'news_content',
            'editor',
            [
                'name' => 'news_content',
                'label' => __('Long Description'),
                'title' => __('Long Description'),
                'style' => 'height:11em',
                'required' => true,
                'disabled' => $isElementDisabled,
                'config' => $wysiwygConfig
                //'config'    => $wysiwygConfig
            ]
        );

        $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
        $timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
        $style = 'color: #000;background-color: #fff; font-weight: bold; font-size: 13px;';
       $fieldset->addField(
            'start_time',
            'date',
            [
                'name' => 'start_time',
                'label' => __('Starting time'),
                'title' => __('Starting time'),
                'required' => true,
                'readonly' => true,
                'style' => $style,
                'class' => 'required-entry',
                'date_format' => $dateFormat,
                'time_format' => $timeFormat,
            ]
        );

I hope this will help you.