0

In Magento 2.2.5, I am trying to add dependency field for the admin form dropdown (select type) dependency field.

I am followed this ref. It is working for text type field dependency. But not working for the dropdown hide field.

Here is my code:

$selectType = array(''=> "--- Select Type ---", 1 => "Type 1", 2 => "Type 2", 3 => "Type 3");
$selectField = $fieldset->addField(
        'publish-type',
        'select',
        [
            'name' => 'merchant-type',
            'label' => __('Publish To'),
            'title' => __('Publish To'),
            'required' => false,
            'options' => $selectType
        ]

    );

    $hideField = $fieldset->addField(
        'merchant-type',
        'select',
        [
            'name' => 'merchant-type',
            'label' => __('Select Merchant Type to Publish'),
            'title' => __('Select Merchant Type to Publish'),
            'required' => false,
            'options' => $mycustomArray
        ]

    );
$dependence = $this->getLayout()->createBlock(
        'Magento\Backend\Block\Widget\Form\Element\Dependence')
        ->addFieldMap($selectField->getHtmlId(), $selectField->getName())
        ->addFieldMap($hideField->getHtmlId(), $hideField->getName())
        ->addFieldDependence($hideField->getName(),$selectField->getName(),2);

I want to implement for multiple fields like this. It is not working.

Your Answer

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

Browse other questions tagged or ask your own question.