It is possible to add 2 depedencies to 1 field?
Like this?
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 1'
)
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
'dependecy 2'
)
With this code it looks like only add the first dependency
Can i also indicate if the $field_to_show hides insteand of show?
2 Answers 2
Edit
This seem to be an issue in Magento2, one possible workaround is
In your construct inject FieldFactory and also create a protected var for _fieldFactory
public function __construct(
......
\Magento\Config\Model\Config\Structure\Element\Dependency\FieldFactory $fieldFactory,
......
) {
....
$this->_fieldFactory = $fieldFactory;
....
}
Then update your existing code to
$refField = $this->_fieldFactory->create(
['fieldData' => ['value' => 'dependecy 1,dependecy 2', 'separator' => ','], 'fieldPrefix' => '']
);
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
$refField
)
I created an issue for this at https://github.com/magento/magento2/issues/4796
Try
->addFieldMap($field_to_evaluate->getHtmlId(), $field_to_evaluate->getName())
->addFieldMap($field_to_show->getHtmlId(), $field_to_show->getName())
->addFieldDependence
(
$field_to_show->getName(),
$field_to_evaluate->getName(),
array('dependecy 1','dependecy 2')
)
To hide the field by default, you should set the default selected value of that option to the option that would trigger it to hide (to prevent any UI confusion)
-
I tried that, did not work get error
Notice: Array to string conversiontaking a look at\vendor\magento\module-backend\Block\Widget\Form\Element\Dependence.phpthe first dependency gets overwritten by the seconed if a separe it$this->_depends[$fieldName][$fieldNameFrom] = $refField;Gianni Di Falco– Gianni Di Falco2016年05月31日 06:57:00 +00:00Commented May 31, 2016 at 6:57 -
Wow ty for your interest, have not tried it yet but it seems it may workGianni Di Falco– Gianni Di Falco2016年06月13日 06:49:38 +00:00Commented Jun 13, 2016 at 6:49
$refField = $this->_fieldFactory->create(['fieldData' => ['value' => '1,2', 'separator' => ','], 'fieldPrefix' => '']
);
$this->setChild('form_after', $this->getLayout()->createBlock(
'Magento\Backend\Block\Widget\Form\Element\Dependence')
->addFieldMap($action->getHtmlId(), $action->getName())
->addFieldMap($anotherFieldweb->getHtmlId(), $anotherFieldweb->getName())
->addFieldMap($anotherFieldstore->getHtmlId(), $anotherFieldstore->getName())
->addFieldMap($anotherFieldhideorders->getHtmlId(), $anotherFieldhideorders->getName())
->addFieldMap($anotherFieldhideinvoice->getHtmlId(), $anotherFieldhideinvoice->getName())
->addFieldMap($anotherFieldhideshipment->getHtmlId(), $anotherFieldhideshipment->getName())
->addFieldMap($anotherFieldhidecredit->getHtmlId(), $anotherFieldhidecredit->getName())
->addFieldDependence($anotherFieldweb->getName(),$action->getName(),1)
->addFieldDependence($anotherFieldstore->getName(),$action->getName(),2)
->addFieldDependence($anotherFieldhideorders->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideinvoice->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhideshipment->getName(),$action->getName(),$refField)
->addFieldDependence($anotherFieldhidecredit->getName(),$action->getName(),$refField)
);
-
This is perfect solutionmilan Thakkar– milan Thakkar2019年04月04日 06:41:03 +00:00Commented Apr 4, 2019 at 6:41
Explore related questions
See similar questions with these tags.