You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

62 line
1.7 KiB

  1. Autosuggest
  2. ===========
  3. Adapted from: Timothy Groves - http://www.brandspankingnew.net
  4. .. data:: cur_autosug
  5. Live Autosuggest object
  6. .. function:: hide_autosuggest()
  7. Hide the Live Autosuggest (if exists)
  8. .. class:: AutoSuggest(id, param)
  9. Create a new autosuggest object
  10. Overriding the default call
  11. ---------------------------
  12. * To override the default server call, override the method `doAjaxRequest`
  13. * To override updation in the INPUT element, override the method `custom_select`
  14. Example
  15. -------
  16. Example where email id is to be retrieved::
  17. // ---- add auto suggest ----
  18. var opts = { script: '', json: true, maxresults: 10 };
  19. var as = new AutoSuggest(d.widgets['To'], opts);
  20. as.custom_select = function(txt, sel) {
  21. // ---- add to the last comma ----
  22. var r = '';
  23. var tl = txt.split(',');
  24. for(var i=0;i<tl.length-1;i++) r=r+tl[i]+',';
  25. r = r+(r?' ':'')+sel;
  26. if(r[r.length-1]==NEWLINE) r=substr(0,r.length-1);
  27. return r;
  28. }
  29. // ---- override server call ----
  30. as.doAjaxRequest = function(txt) {
  31. var pointer = as; var q = '';
  32. // ---- get last few letters typed ----
  33. var last_txt = txt.split(',');
  34. last_txt = last_txt[last_txt.length-1];
  35. // ---- show options ----
  36. var call_back = function(r,rt) {
  37. as.aSug = [];
  38. if(!r.cl) return;
  39. for (var i=0;i<r.cl.length;i++) {
  40. as.aSug.push({'id':r.cl[i], 'value':r.cl[i], 'info':''});
  41. }
  42. as.createList(as.aSug);
  43. }
  44. $c('get_contact_list',{'select':_e.email_as_field, 'from':_e.email_as_dt, 'where':_e.email_as_in, 'txt':(last_txt ? strip(last_txt) : '%')},call_back);
  45. return;
  46. }