English 中文(简体)
Jqgrid + JQuery Autocomplete 多重投入
原标题:Jqgrid + JQuery Autocomplete multiple input

I have the grid set up and working nicely. I wanted to add multiple input autocomplete functionality to the form view in JqGrid. The multiple autocomplete works but the extractLast function seems not to be working and I can add duplicate inputs. Heres the code:

var availableTags = [
        "ActionScript",
        "AppleScript",
        "Asp",
        "BASIC",
        "C",
        "C++",
        "Clojure",
        "COBOL",
        "ColdFusion",
        "Erlang",
        "Fortran",
        "Groovy",
        "Haskell",
        "Java",
        "JavaScript",
        "Lisp",
        "Perl",
        "PHP",
        "Python",
        "Ruby",
        "Scala",
        "Scheme"
    ];
function split( val ) {
        return val.split( /,s*/ );
        }
        function extractLast( term ) {
            return split( term ).pop();
        }
        function autocomplete_element(value, options) {
          // creating input element
          var $ac = $( <input type="text"/> );
          // setting value to the one passed from jqGrid
          $ac.val(value);
          // creating autocomplete
          $ac.autocomplete(
                {source: function( request, response ) {
                // delegate back to autocomplete, but extract the last term
                response( $.ui.autocomplete.filter(
                    availableTags, extractLast( request.term ) ) );
            },

                focus: function() {
                    // prevent value inserted on focus
                    return false;
                },
                select: function( event, ui ) {
                    var terms = split( this.value );
                    // remove the current input
                    terms.pop();
                    // add the selected item
                    terms.push( ui.item.value );
                    // add placeholder to get the comma-and-space at the end
                    terms.push( "" );
                    this.value = terms.join( ", " );
                    return false;
                }
            });
          // returning element back to jqGrid
          return $ac;
        }
        function autocomplete_value(elem, op, value) {
          if (op == "set") {
            $(elem).val(value);
          }
          return $(elem).val();
        }

Grid colmodel:

{
                ...
                editable: true,
                edittype: "custom",
                editoptions: {
                    custom_element: autocomplete_element,
                    custom_value: autocomplete_value
                }
            },

我从

and German Rumm s blog

任何建议?

www.un.org/spanish/ecosoc UPDATED!

问题回答

例如,在j Query UI网站也允许选择同样的要素。 问题载于<代码>源代码功能——在设定建议清单时,总是对照所有现有术语对最后一段进行核对。

更改<代码> 选择后只显示尚未在外地存在的术语。

source: function(request, response) {
  var terms = request.terms.split(/,s*/);
  var last_term = terms.pop();

  var tags = $.grep(availableTags, function(el) {
    return $.inArray(el, terms) == -1);
  });

  response($.ui.autocomplete.filter(tags, last_term))
}




相关问题
high load on mysql DB how to avoid?

I have a table contain the city around the worlds it contain more than 70,000 cities. and also have auto suggest input in my home page - which used intensively in my home page-, that make a sql query ...

Fast Javascript String Replacement

Hey there geniuses of SO! This is for an autocomplete plugin that needs to accept data as an array of arrays and convert it using a format string (or regex). The format string could be any format. ...

Categorized results – jQuery autocomplete plugin

I m looking for an autocomplete plugin that makes it easy to categorize search results. If that s unclear, take a look at Apple.com s search bar (top right). I know that script.aculo.us autocomplete ...

Limiting IntelliJ IDEA import suggestions on completion

When I type the name of a class which will need to be imported, IntelliJ lovingly pops up with a list of suggestions. However, most of the time those suggestions are things I d never want to import, ...

热门标签