How to set dependency of admin form field in magento 2?
How can i set dependency of admin fields
I am trying this code
$this->setChild('form_after',
$this->getLayout()->createBlock('Magento\Backend\Block\Widget\Form\Element\Dependence')
->addFieldMap('answers', 'answer')
->addFieldMap('is_status', 'status')
->addFieldDependence('status', 'answer', 'Customer')
);
but its not working
EDIT
protected function _prepareForm()
{
......
$model = $this->_coreRegistry->registry('answers');
$form = $this->_formFactory->create();
$form->setHtmlIdPrefix('page_');
$fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Answer Information')]);
if ($model->getId()) {
$fieldset->addField('answers_id', 'hidden', ['name' => 'answers_id']);
}
$fieldset->addField(
'answers',
'select',
[
'label' => __('Answer'),
'title' => __('Answer'),
'name' => 'answers',
options => $this->_answerby->getOptionArray(),
]
);
$fieldset->addField(
'is_status',
'text',
[
'label' => __('Status'),
'title' => __('Status'),
'name' => 'is_status',
]
);
$this->setChild('form_after',
$this->getLayout()->createBlock('Magento\Backend\Block\Widget\Form\Element\Dependence')
->addFieldMap('answers', 'answer')
->addFieldMap('is_status', 'status')
->addFieldDependence('status', 'answer', 'Customer')
);
$form->setValues($model->getData());
$this->setForm($form);
return parent::_prepareForm();
}