Read More
Read More
Menu Close

    Depend an attribute field on other attribute’s field in admin form magento2

    If you are working on your magento, to implement functionality releated to magento’s product’s attribute,  and if you are displaying them in admin product form, and want to depend one of the field on other field’s value then this blog is helpful for you.

    For example:
    You have two attribute of product: field_main and field_sub.
    Your attribute field_sub is dependent on field_main attribute’s value.
    Now, you need to add following code in your plugin:

    firstly you have to create a file at path:

    Now define your attribute’s data provider:

    create file at path:



    Searching for an experienced
    Magento 2 Company ?
    Read More

    in di.xml we map the field’s data provider.

    in fieldSub.php file,

    modifyMeta() calls to modify the attribute, in this function we added additional checks to our field, which are:

    data_scope: is the name of the field (field code)

    validation: validations which we want to apply on our filed.

    additionalClasses : if want to add additional class to our field.

    imports: in this we pass the attributes value, like: disabled, product-id, or any other attribute to add in element.

    After this flush the cache, and your field (field_sub) will be dependent on other field’s (field_main) value.


    I hope this blog will help you to implement your functionality in magento2.

    Thank you.

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top