1

I need the product field "disabled" attribute to be dependent from two other checkbox fields. For now I have it dependent from one field like this (DataModfier):

protected function customizeFieldSub(array $meta)
{
 $dependentPath = $this->arrayManager->findPath('show_email_for_instant_price', $meta, null, 'children');
 if ($dependentPath) {
 $meta = $this->arrayManager->merge(
 $dependentPath . static::META_CONFIG_PATH,
 $meta,
 [
 'dataScope' => 'dependent_field',
 'validation' => [
 'required-entry' => true,
 'validate-zero-or-greater' => true
 ],
 'formElement' => 'input',
 'additionalClasses' => 'admin__field-small',
 'imports' => [
 'disabled' => 
 '!ns = ${ $.ns }, index = field1:checked'
 ]
 ]
 );
 }
 return $meta;
}

I need something like this:

 'imports' => [
 'disabled' =>
 '(!ns = ${ $.ns }, index = field1:checked) && (!ns = ${ $.ns }, index = field2:checked)'
 ]

But it doesn't work this way. And also it doesn't allow to use functions there. How can I achieve what I want? I need the field to be disabled until you enable two checkboxes

vitoriodachef
3,5801 gold badge26 silver badges70 bronze badges
asked Jun 17, 2019 at 17:56

1 Answer 1

1

Following are 2 different solutions for handling field dependency:

https://www.hungersoft.com/info/dependent-fields-ui-component-form-magento2-boolean-fields

https://www.hungersoft.com/info/dependent-fields-ui-component-form-magento2-without-js

I have tried both the solutions and they work for simple cases such as field dependency on Yes/No values, a list a values, etc. The solutions discussed are using XML, but you should be able to convert the logic to array.

answered Dec 19, 2019 at 5:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.