0

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

0

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("");
            }
        },
    });
});  
  • when change category cms_page selected index is null but it takes old selected values – Dipak Solanki Jul 28 '18 at 12:38
  • Did you deleted selectOptionCategory? this is not needed anymore. – Sohel Rana Jul 28 '18 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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