Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 2.18 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Trigger autocomplete using button/emulate combobox functionality
  2. initImpactEdit = function (elem) {
  3.             setTimeout(function () {
  4.                 $(elem).autocomplete({
  5.                     source: function (request, response) {
  6.                         $.ajax({
  7.                             url: '@Url.Action("ImpactOptions")',
  8.                             dataType: "json",
  9.                             data: {
  10.                                 filter: request.term
  11.                             },
  12.                             success: function (data) {
  13.                                 response($.map(eval(data), function (item) {
  14.                                     return {
  15.                                         label: item.Impact_name,
  16.                                         value: item.Impact_name,
  17.                                         DTI_ID: item.DTI_ID
  18.                                     }
  19.                                 })
  20.                             );
  21.                             }
  22.                         })
  23.                     }
  24.                     }
  25.                 });
  26.  
  27.             $(elem).addClass('customAutoCompleteWidth');
  28.  
  29.             $('<button class="customDropdown"> </button>')
  30.             .attr("tabIndex", -1)
  31.             .attr("title", "Show All Items")
  32.             .insertAfter(elem)
  33.             .button({
  34.                 icons: {
  35.                     primary: "ui-icon-triangle-1-s"
  36.                 },
  37.                 text: false
  38.             })
  39.             .removeClass("ui-corner-all")
  40.             .addClass("ui-corner-right ui-button-icon")
  41.             .click(function () {
  42.                 var widg = $(elem);
  43.  
  44.                 if (widg.autocomplete("widget").is(":visible")) {
  45.                     widg.autocomplete("close");
  46.                     return;
  47.                 }
  48.  
  49.                 if (widg.val().length == 0) {
  50.                     // pass empty string as value to search for, displaying all results
  51.                     widg.autocomplete("search", "*");
  52.                 } else { widg.autocomplete("search", widg.val()); }
  53.                 widg.focus();
  54.             });
  55.  
  56.             }, 100);
  57.         };
  58.  
  59. { name: 'Impact', index: 'Impact', editoptions: { dataInit: initImpactEdit  } },