EasyUI Forum
April 30, 2024, 01:09:22 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Combobox onClick/loader  (Read 9358 times)
jega
Full Member
***
Posts: 190


View Profile
« on: December 26, 2016, 05:56:35 AM »

Have a strange problem

Having a combobox

    <input id="unitSearch" name="unitSearch" class="easyui-combobox" style="width:300px" data-options="
       loader: unitsLoader,
       mode: 'remote',
       valueField: 'id',
       textField: 'name',
       formatter: formatItem,
       hasDownArrow: false,
       iconCls:'icon-search',
       prompt: 'Indtast søgeord'">

A loader

    var unitsLoader = function(param,success,error){
        var searchWord = param.q || '';
      if (searchWord.length <= 1){return false}
        $.ajax({
            url: 'getfromdb.asp',
            dataType: 'jsonp',
            data: {
                sw: searchWord,
                st: 'unitsearch',
            },
            success: function(data){
                var items = $.map(data, function(item,index){
                       return {
                        id: item.unitID,
                        name: item.unitName,
                        fv: item.unitFV
                    };
                });
                success(items);
            },
            error: function(){
                error.apply(this, arguments);
            }               
        });
    }

And a formater

   function formatItem(row){
      var s = '<span style="font-weight:bold">' + row.name + '</span><br/>' +
      '<span style="color:#888">' + row.fv + '</span>';
      return s;
   }


Then i have this script code

   $( document ).ready(function(){
      $('#unitSearch').combobox('textbox').keyup(function(e){
         //console.log(e.keyCode);
         if (e.keyCode == 13){
            findNode($('#unitSearch').combobox('getValue'));
         }
      });
   });


Everything working perfect. Show items in combobox depending on searchword. Press enter on an item, it show the node in the tree.


Now i add the following code, because i want to findNode when onClick


   $('#unitSearch').combobox({
      onClick: function(r){
         //console.log(r)
         findNode(r.ID);
      }
   });

Nothing Works now. The loader is not called. So no result to the combobox

Anyone that can explain why ??


regards
Jesper
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: December 26, 2016, 07:07:49 AM »

When click on a item of the combobox, the 'onClick' event fires. Please look at your code
Code:
   $('#unitSearch').combobox({
      onClick: function(r){
         console.log(r)
         findNode(r.ID);
      }
   });
You may pass a wrong field value to the 'findNode' function. It may be findNode(r.id).
Logged
jega
Full Member
***
Posts: 190


View Profile
« Reply #2 on: December 26, 2016, 07:35:39 AM »

Hi jarry.

Yes the r.ID had to be r.id, BUT thats not the main problem

When i add the script

   $('#unitSearch').combobox({
      onClick: function(r){
         //console.log(r)
         findNode(r.id);
      }
   });

The loader is never called, and then it never calls getfromdb.asp.

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!