EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Coder on March 31, 2017, 12:06:18 AM



Title: [SOLVED] dynamically change option 'required'
Post by: Coder on March 31, 2017, 12:06:18 AM
in html:

Code:
 <input id="iCheck" 
    class="easyui-switchbutton"
    data-options="onChange:iCheckChange"
 >
 <input id="iCombo"
    class="easyui-combobox"
    data-options="mode:'remote'
                , disabled: true
                , required: false
                , loader: ...
                "
  >
in script

Code:
function iCheckChange(aChecked){
  $('#iCombo').combobox(aChecked?'enable':'disable').combobox('options').required = aChecked;
};

Code: https://jsfiddle.net/0dbog4of/4/

How change style dynamically?


Title: Re: Change option 'required' dynamically didnt redraw visual style of component
Post by: jarry on April 01, 2017, 05:52:06 AM
Please try this code.
Code:
function iCheckChange(aChecked){
  $('#iCombo').combobox(aChecked?'enable':'disable');
  $('#iCombo').combobox('options').required = aChecked;
  $('#iCombo').combobox('textbox').validatebox('options').required = aChecked;
  $('#iCombo').combobox('validate');
};


Title: [SOLVED] Change option 'required' dynamically - redraw visual style of component
Post by: Coder on April 01, 2017, 04:56:50 PM
Thnx, its worked!


Title: Re: [SOLVED] dynamically change option 'required'
Post by: y.bykov on May 29, 2019, 05:40:34 AM
Who wants to use required dynamically it's better to use combobox methods extensension.
Code:
Object.assign($.fn.combobox.methods, {
        require: function(jq, value) {
            return jq.each(function() {
                const $combobox = $(this);

                value = value === undefined ? true : Boolean(value);

                $combobox.combobox('options').required = value;
                $combobox.combobox('textbox').validatebox('options').required = value;
                $combobox.combobox('validate');
            });
        },
    });