Bijay Thapa
Bijay Thapa

Reputation: 380

Setting the value of textfield on combobox change- easyui

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.

Upvotes: 2

Views: 12525

Answers (2)

Maher Asad
Maher Asad

Reputation: 1

Code:

 onSelect: function(rec){
           var row = $('#tblCoursefaculty').datagrid('getSelected');
           var rowIndex = $('#tblCoursefaculty').datagrid('getRowIndex', row)
          var editors = $('#tblCoursefaculty').datagrid('getEditors', rowIndex);
              var ed_fc_co_section = editors[8];
                       $(ed_fc_co_section.target).val(rec.co_section);
                       var ed_fc_co_course_cr = editors[9];
                       $(ed_fc_co_course_cr.target).val(rec.co_course_cr);                              }                                                                      
 }               }">Course</th>
<th data-options="field:'fc_co_section',width:50,align:'left',editor:'text'">Section</th>
<th data-options="field:'fc_co_course_cr',width:50,align:'left',editor:'text'">Credit Hour</th>  

Upvotes: 0

bipen
bipen

Reputation: 36531

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');

                }
            }

Upvotes: 2

Related Questions