cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide particular admin form field(UI Component) based on the value of select field?

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

How to hide particular admin form field(UI Component) based on the value of select field?

I used the following script and it is working fine. But I want to hide/display the fields without changing the select field options(once the form load completed).

 

define([
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/select',
    'Magento_Ui/js/modal/modal'
], function (_, uiRegistry, select, modal) {
    'use strict';



    return select.extend({

        /**
         * On value change handler.
         *
         * @param {String} value
         */
         onUpdate: function (value) {
            
            var sdate = uiRegistry.get('index = schedule_date');

            if(value==1){

                sdate.show();
            } else {
                sdate.hide();
            }

            return this._super();
        }
    });
});

 

 

Prema M
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to hide particular admin form field(UI Component) based on the value of select field?

Finally, I found a solution to this requirement. While the select field gets initialized, based on its value it, we can hide/display the corresponding fields.

initialize: function () {
            this._super();
            if (this.customEntry) {
                registry.get(this.name, this.initInput.bind(this));
            }
            if (this.filterBy) {
                this.initFilter();
            }
            var sdate = uiRegistry.get('index = schedule_date');
            if(this.value()==1){
                sdate.show();
            } else {
                sdate.hide();
            }
            return this;
        }
Prema M

View solution in original post

2 REPLIES 2

Re: How to hide particular admin form field(UI Component) based on the value of select field?

Finally, I found a solution to this requirement. While the select field gets initialized, based on its value it, we can hide/display the corresponding fields.

initialize: function () {
            this._super();
            if (this.customEntry) {
                registry.get(this.name, this.initInput.bind(this));
            }
            if (this.filterBy) {
                this.initFilter();
            }
            var sdate = uiRegistry.get('index = schedule_date');
            if(this.value()==1){
                sdate.show();
            } else {
                sdate.hide();
            }
            return this;
        }
Prema M

Re: How to hide particular admin form field(UI Component) based on the value of select field?

Hi,

 

Can you please keep the whole code of that file.I tried the same way but in mycase the field is not hiding

 

Thanks in advance