2

Custom ui component select(Dropdown)

<select class="admin__control-select" data-bind="  
    event:{ change: selectOptionCategory(uid)},  
    attr: {  
        name: inputName,  
        id: uid,  
        disabled: disabled,  
        'aria-describedby': noticeId  
    },  
    hasFocus: focused,  
    optgroup: options,  
    value: value,  
    optionsCaption: caption,  
    optionsValue: 'value',  
    optionsText: 'label'"/>  

Custom ui component js

define([  
    'jquery',  
    'Magento_Ui/js/form/element/select'  
], function ($, Select) {  
    'use strict';  
    return Select.extend({  
        defaults: {  
            customName: '${ $.parentName }.${ $.index }_input'  
        },  
        /**  
        * Change currently selected option  
        *  
        * @param {String} id  
        */  
        selectOptionCategory: function(id){  
            if(($("#"+id).val() != 0)) {  
                $('div[data-index="cms_page"] select').val("");  
            }  
        },  
    });  
});  

I want to clear selected value of cms_page dropdown when I click category dropdown but it give old value

1 Answer 1

1

Added following function


onUpdate: function () {
    this._super();
    console.log(this.value())
}

Now you components looks like


define([
    'jquery',
    'Magento_Ui/js/form/element/select'
], function ($, Select) {
    'use strict';
    return Select.extend({
        defaults: {
            customName: '${ $.parentName }.${ $.index }_input'
        },
        onUpdate: function () {
            this._super();
            if((this.value() != 0)) {
                $('div[data-index="cms_page"] select').val("");
            }
        },
    });
});  
2
  • when change category cms_page selected index is null but it takes old selected values Commented Jul 28, 2018 at 12:38
  • Did you deleted selectOptionCategory? this is not needed anymore.
    – Sohel Rana
    Commented Jul 28, 2018 at 14:17

Your Answer

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

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