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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.