I'm working with magento 2. when i want to set required for Gender field in Admin. It required me to config something.
-
can you explain more?– Ajay PatelApr 8, 2016 at 4:47
-
I think it is asking to specify gender options. Magento does not know the values for gender dropdown automatically.– Mohit Kumar AroraMay 9, 2018 at 13:57
3 Answers
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.
I think it is asking to specify gender options. Magento does not know the values for gender dropdown automatically.
You just have to specify values for the gender dropdown.
Add like this :-
$fieldset->addField(
'news_short_description',
'editor',
[
'name' => 'news_short_description',
'label' => __('Short Description'),
'title' => __('Short Description'),
'class' => 'validate-length maximum-length-100',
'required' => true
]
);