Menu Close
    Hire us Request quote Reading list Switch to dark mode

    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:



    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:

    . . .
    Subscribe Articles

    Just enter your email below to subscribe and receive weekly updates about the most interesting similar articles.

    You need to accept conditions to receive letters.
    You've Subscribed!

    Share article via

    . . .

    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.

    . . .


    Add Your Comment

    Be the first to comment.

    Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again