Setting the value of textfield on combobox change- easyui

Bijay Thapa picture Bijay Thapa · Feb 15, 2013 · Viewed 12.1k times · Source

Below is the part of my rows. I need to change the value of BudgetLineItemCode field when combobox value is changed.

{ title: 'Index', field: 'RootLevel', width: 50, editor: { 'type': 'validatebox', 'options': { required: true}} },
            { field: 'PHeading', title: 'Heading', width: 240,
                formatter: function (value) {
                    for (var i = 0; i < CItems.length; i++) {

                        if (CItems[i].heading.toLowerCase() == value.toLowerCase()) {
                            return CItems[i].heading;
                    }
                    return value;
                },
                editor: {
                    type: 'combobox',
                    options: {
                        valueField: 'heading',
                        textField: 'heading',
                        data: CItems,
                        required: true
                        onSelect: function (record) {
                        var selrow = $('#trgrid').treegrid('getSelected');
                        var rowIndex = $('#trgrid').treegrid('find',row.BudgetDetailID)
                        var editors =$('#trgrid').treegrid('getEditors',selrow.BudgetDetailID);

                     var codeEditor = editors[2];

                     $(codeEditor.target).text('setValue', 'newval');

                    }
                }
            }{ title: 'Code', field: 'BudgetLineItemCode', width: 50, editor: { 'type': 'text'} }

Also, One more question. There is no onChange event for combobox. Is there any way we can get past this. I mean like i may want to check for the code as user types in the combobox.

Answer

bipen picture bipen · Feb 15, 2013

for the first part you can do

$(codeEditor.target).val('newval');

since setters for validatebox is .val(),

docs here..

and for second easyui combobox does that by default.. or you can use keyhandler

editor: {
                type: 'combobox',
                options: {
                    valueField: 'heading',
                    textField: 'heading',
                    data: CItems,
                    required: true,
                    keyHandler: {
                    up: function(){},
                    down: function(){},
                    enter: function(){},
                    query: function(q){ console.log(q)} //<----here
                    },
                    onSelect: function (record) {
                    var selrow = $('#trgrid').treegrid('getSelected');
                    var rowIndex = $('#trgrid').treegrid('find',row.BudgetDetailID)
                    var editors =$('#trgrid').treegrid('getEditors',selrow.BudgetDetailID);

                 var codeEditor = editors[2];

                 $(codeEditor.target).text('setValue', 'newval');

                }
            }