<NME> jquery.flexdatalist.min.js
<BEF> jQuery.fn.flexdatalist=function(e,t){"use strict";var i,a=$(document),s=$(this),n=this;if(i=function(){var t,i,a=$(this),s={},l="",r=null;a.attr("name");a.hasClass("flexdatalist-set")&&n._destroy(a),n._options(a,$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"],searchContain:!1,searchEqual:!1,searchDisabled:!1,normalizeString:null,multiple:a.attr("multiple"),maxShownResults:100,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,_values:[]},a.data(),"object"==typeof e?e:{})),a._options=function(e,t){return n._options(a,e,t)},a._init=function(){var e=a._options();t=a.clone(!1).attr({list:null,name:null,id:a.attr("id")?a.attr("id")+"-flexdatalist":null}).addClass("flexdatalist-alias").removeClass("flexdatalist"),a._options("multiple")?(i=$("<ul>").addClass("flexdatalist-multiple").css({"border-color":a.css("border-left-color"),"border-width":a.css("border-left-width"),"border-style":a.css("border-left-style"),"border-radius":a.css("border-top-left-radius")}).insertAfter(a).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(i)):t.insertAfter(a),t.attr("autofocus")&&t.focus(),t.on("input keydown",function(i){var s=a._keyword();188===n._keyNum(i)&&!e.selectionRequired&&e.multiple?(i.preventDefault(),a._value(s),a._removeResults()):9===n._keyNum(i)?a._removeResults():0===s.length&&e.multiple&&8===n._keyNum(i)&&t.data("_remove",t.parents("li:eq(0)").prev())}).on("input keyup",function(i){if(a._changed()&&13!==n._keyNum(i)){var s=a._keyword();s.length>=e.minLength?a._search(function(e){a._showResults(e)}):a._removeResults(),e.multiple||(e.selectionRequired?a._value(""):a._value(s))}var r=t.data("_remove");r&&(r.find(".fdl-remove").click(),t.data("_remove",null)),l=a._keyword()}).focus(function(){var t=a._keyword();0===e.minLength?""===t&&a._tdata(function(e){a._showResults(e)}):t.length>=e.minLength&&!a._selected()&&a._search(function(e){a._showResults(e)})}).attr("autocomplete","off"),window.onresize=function(){a._position()},a.addClass("flexdatalist flexdatalist-set").attr("type","hidden")},a._changed=function(){return l!==a._keyword()},a._chained=function(){var e=a._options();if(e.relatives&&e.chainedRelatives){var l=function(s){e.relatives.each(function(){var l=n._isEmpty($(this).val()),r=n._isEmpty(a.val());t.prop("disabled",l),s||!l&&r||(a._value(""),t.val(""),e.multiple&&i.find("li .remove").click()),i&&(l&&i?i.addClass("disabled"):i.removeClass("disabled"))})};e.relatives.on("change",function(){l(),s={}}),l(!0)}},a._initValue=function(){var e=a.attr("value");n._isEmpty(e)||(a._options("originalValue",a.val()),a._parseValue(e,function(e){a.val("",!0),t.val(""),n._isEmpty(e)||a._values(e),l=a._keyword()}))},a._parseValue=function(e,t){var i=a._options();if(a._toJSON())try{t(JSON.parse(e))}catch(s){}else if(a._toCSV()||"string"==typeof i.valueProperty){var n=e.split(",");if("string"==typeof i.valueProperty){var l=i.searchIn;i.searchIn=i.valueProperty.split(","),i.searchEqual=!0,a._search(function(e){e.length>0&&t(e),i.searchIn=l,i.searchEqual=!1},n)}else t(n)}else t(e)},a._tdata=function(e){a.trigger("before:flexdatalist.data"),a._url(function(t){a._data(function(i){i=i.concat(t);for(var s=a._options("_values"),n=0;n<i.length;n++){var l=i[n];s&&s.indexOf(a._getText(l))>-1&&delete i[n]}a.trigger("after:flexdatalist.data",[i]),e(i)})})},a._data=function(e){var t=a._options();"string"==typeof t.data?a._remote({url:t.data,success:function(i){var s=a._getRemoteData(i);t.data=s,e(s)}}):e(t.data)},a._url=function(e){var t=a._options(),i=a._keyword(),s=a.val(),l=i;return n._isEmpty(t.url)?e([]):(clearTimeout(r),void(r=setTimeout(function(){t.cache&&2!==t.cache&&(l=i.substring(0,t.minLength>0?t.minLength:1));var n=a._cache(l);return n?void e(n):(delete t.relatives,delete t._values,void a._remote({url:t.url,data:$.extend(a._relativesData(),t.params,{keyword:i,contain:t.searchContain,selected:s,options:t}),success:function(t){var s=a._getRemoteData(t),n=a._keyword();n.length>i.length?a._search(function(e){a._showResults(e)}):e(s),a._cache(l,s)}}))},200)))},a._remote=function(e){a.hasClass("flexdatalist-loading")||(a.addClass("flexdatalist-loading"),e=$.extend({type:"post",dataType:"json",complete:function(){a.removeClass("flexdatalist-loading")}},e),$.ajax(e))},a._getRemoteData=function(e){var t=e.results?e.results:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t.options&&n._options(a,t.options),n._isObject(t)?t:[]},a._relativesData=function(){var e=a._options("relatives"),t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t},a._datalist=function(){var e=a._options(),t=a.attr("list");return n._isEmpty(t)||(e.data=[],$("#"+t).find("option").each(function(){var t=$(this),i=t.val(),a=t.text();e.data.push({label:a.length>0?a:i,value:i})})),a},a._cache=function(e,t){if(a._options("cache")){if(e=a._normalizeString(e),!n._isDefined(t))return n._isDefined(s,e)&&(t=s[e]),t;s[e]=t}return null},a._search=function(e,t){a._tdata(function(i){var s=[],l=a._options();if(l.searchDisabled)return e(i);n._isDefined(t)||(t=a._keyword()),"string"==typeof t&&(t=[t]),a.trigger("before:flexdatalist.search",[t,i]);for(var r=0;r<t.length;r++)for(var o=t[r],u=0;u<i.length;u++){var d=a._matches(i[u],o,l.values);d&&s.push(d)}a.trigger("after:flexdatalist.search",[t,i,s]),e(s)})},a._matches=function(e,t){for(var i=!1,s=$.extend({},e),l=a._options(),r=l.searchIn,o=0;o<r.length;o++){var u=r[o];if(n._isDefined(e,u)&&e[u]){var d=e[u].toString();a._find(t,d)&&(s[u+"_highlight"]=a._highlight(t,d),i=!0)}}return i?s:null},a._highlight=function(e,t){return t.replace(new RegExp(e,a._options("searchContain")?"ig":"i"),'<span class="highlight">$&</span>')},a._find=function(e,t){var i=a._options();return t=a._normalizeString(t),e=a._normalizeString(e),i.searchEqual?t==e:i.searchContain?t.indexOf(e)>=0:0===t.indexOf(e)},a._showResults=function(e){a._removeResults(!0);var t=a._options();if(0===e.length)return void a._noResults(t.noResultsText);var i=a._getResultsContainer();t.groupBy?(e=a._groupData(e),Object.keys(e).forEach(function(s){var n=e[s],l=t.groupBy,r=a._getHighlight(n[0],l,s);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(r)).append($("<span>").addClass("group-item-count").text(" "+n.length)).appendTo(i);a._items(n,i)})):a._items(e,i);var s=i.find("li:not(.group)");s.on("click",function(){var e=$(this).data("item");e&&(a._selected(!0)._removeResults()._value(e),a.trigger("select:flexdatalist",[e,t]))}).hover(function(){s.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),t.focusFirstResult&&s.filter(":first").addClass("active")},a._noResults=function(e){if(!n._isEmpty(e)){var t=a._getResultsContainer(),i=a._keyword();e=e.split("{keyword}").join(i),$("<li>").addClass("item no-results").append(e).appendTo(t)}},a._groupData=function(e){for(var t=[],i=a._options("groupBy"),s=0;s<e.length;s++){var l=e[s];if(n._isDefined(l,i)){var r=l[i];n._isDefined(t,r)||(t[r]=[]),t[r].push(l)}}return t},a._items=function(e,t){var i=a._options("maxShownResults");a.trigger("show:flexdatalist.results",[e]);for(var s=0;s<e.length&&!(i>0&&i===s);s++)a._item(e[s]).appendTo(t);a.trigger("shown:flexdatalist.results",[e])},a._item=function(e){for(var t=$("<li>").data("item",e).addClass("item"),i=a._options(),s=i.visibleProperties,l=0;l<s.length;l++){var r=s[l];if((!i.groupBy||i.groupBy!==r)&&n._isDefined(e,r)){var o={};if("thumb"===r)o=$("<img>").addClass("item item-"+r).attr("src",e[r]);else{var u=a._getHighlight(e,r);o=$("<span>").addClass("item item-"+r).html(u+" ")}o.appendTo(t)}}return t},a._getHighlight=function(e,t,i){return n._isDefined(e,t+"_highlight")?e[t+"_highlight"]:n._isDefined(e,t)?e[t]:i},a._getResultsContainer=function(){var e=a;a._options("multiple")&&(e=i);var s=$("ul.flexdatalist-results");return 0===s.length&&(s=$("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":e.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":e.css("border-bottom-left-radius"),"border-bottom-right-radius":e.css("border-bottom-right-radius")}).data("target",t),a._position()),s},a._removeResults=function(e){var t="ul.flexdatalist-results";return e&&(t="ul.flexdatalist-results li"),$(t).remove(),a},a._selected=function(e){var t="flexdatalist-selected";return n._isDefined(e)?(e?a.addClass(t):a.removeClass(t),a):a.hasClass(t)},a._values=function(e){return $.isArray(e)&&!n._isEmpty(e)?void $.each(e,function(e,t){a._value(t)}):void a._value(e)},a._value=function(e){var s=a._options(),n=a._getText(e),r=a._getValue(e);if(n.length>0&&s._values.push(n),s.multiple){if(""===e)return a;t.val("");var o=$("<li>").addClass("value"+(s.toggleSelected?" toggle":"")).append('<span class="text">'+n+"</span>").append('<span class="fdl-remove">&times;</span>').insertBefore(i.find("li.input-container"));o.find("span.fdl-remove").click(function(){var e=$(this).parent(),t=e.index();if(!e.hasClass("disabled")&&(a._toJSON()||a._toCSV())){var i=a._inputValue();i.splice(t,1),s._values.splice(t,1),a._inputValue(i)}e.remove()}),s.toggleSelected&&o.click(function(){var e=$(this),t=a._inputValue(),i=e.index();if(e.hasClass("disabled")){var l=e.data("_value");t.splice(i,0,l),s._values.splice(i,0,a._getText(l)),e.removeClass("disabled")}else{var l=t.splice(i,1);e.data("_value",l[0]),s._values.splice(i,1),e.addClass("disabled")}a._inputValue(t,n)})}else n&&n!==t.val()&&t.val(n);return a._inputValue(r,n),l=a._keyword(),a},a._inputValue=function(e,t){var i=a._toJSON(),s=a._toCSV();return n._isDefined(e)?(n._isObject(e)&&(i&&!n._isEmpty(e)?e=JSON.stringify(e):s&&(e=e.join(","))),""===e&&a._options("_values",[]),a.val(e,!0),a.trigger("change:flexdatalist",[e,t,a._options()]).trigger("change"),e):(e=a.val(),e?i?e=JSON.parse(e):s&&(e=e.split(",")):(i||s)&&(e=[]),e)},a._getText=function(e){var t=e,i=a._options();return n._isObject(e)&&(t=e[i.searchIn[0]],t=n._isDefined(e,i.textProperty)?e[i.textProperty]:a._replacePlaceholders(e,i.textProperty,t)),$("<div>").html(t).text()},a._getValue=function(e){var t=e,i=a._options();if(n._isObject(e))if(t=e[i.searchIn[0]],"*"===i.valueProperty)t=e;else if(n._isDefined(e,i.valueProperty))t=e[i.valueProperty];else if(a._toJSON()){var t={},s=i.valueProperty,l=i.textProperty;if(l){var r=l;"string"==typeof l&&(r=a._parsePlaceholders(l)),n._isObject(r)&&$.each(r,function(e,t){s.push(t)})}else n._isDefined(e,l)&&s.push(l);$.each(s,function(i,a){n._isDefined(e,a)&&(t[a]=e[a])})}if(i.multiple&&(a._toJSON()||a._toCSV())){var o=a._inputValue();!n._isEmpty(t)&&n._isObject(o)&&(o.push(t),t=o)}return t},a._replacePlaceholders=function(e,t,i){if(n._isObject(e)&&"string"==typeof t){var s=a._parsePlaceholders(t);if(!n._isEmpty(e)&&s)return $.each(s,function(i,a){n._isDefined(e,a)&&(t=t.replace(i,e[a]))}),t}return i},a._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var i={};return t.map(function(e){i[e]=e.slice(1,-1)}),i}return!1},a._normalizeString=function(e){if("string"==typeof e){var t=a._options("normalizeString");return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e},a._keyword=function(){return t.val().replace(/^\s+/,"")},a._toJSON=function(){var e=a._options("valueProperty");return n._isObject(e)||"*"===e},a._toCSV=function(){return!a._toJSON()&&a._options("multiple")},a._position=function(){var e=t;a._options("multiple")&&(e=i),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px","z-index":e.css("z-index")+1})},a._init(),a._datalist(),a._initValue(),a._chained()},this._destroy=function(e){e||(e=s),e.each(function(){var e=$(this).data("flexdatalist");$(this).removeClass("flexdatalist-set").attr("type","text").val(e&&e.originalValue?e.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})},this._reset=function(){this._destroy()},this._setValue=function(e){s.each(function(){var t=$(this),i=t.data("flexdatalist");if(i){if(i.originalValue=e,""==e)return t.val(e,!0).trigger("change:flexdatalist",[e,e,i]).trigger("change"),void(i.multiple&&t.next("ul.flexdatalist-multiple").find("li.value").remove());n._destroy()}})},this._keyNum=function(e){return e.which||e.keyCode},a.data("flexdatalist")||$(document).mouseup(function(e){var t=$(".flexdatalist-results"),i=t.data("target");i&&i.is(":focus")||t.is(e.target)||0!==t.has(e.target).length||t.remove()}).keydown(function(e){var t=$(".flexdatalist-results"),i=t.find("li"),a=i.filter(".active"),s=a.index(),l=i.length,r=n._keyNum(e);if(0!==l)if(13===r)e.preventDefault(),a.click();else if(40===r||38===r){e.preventDefault(),40===r?a=l>s&&a.nextAll(".item").first().length>0?a.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===r&&(a=s>0&&a.prevAll(".item").first().length>0?a.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active"));var o=(0===a.prev().length?a:a.prev()).position().top;t.animate({scrollTop:o+t.scrollTop()},100)}}).data("flexdatalist",!0),this._isEmpty=function(e){return n._isDefined(e)?null===e?!0:e===!0?!1:0===this._length(e)?!0:""===$.trim(e):!0},this._isObject=function(e){return e&&"object"==typeof e},this._csvToArray=function(e,t){return 0===e.length?t:"string"==typeof e?e.split(","):e},this._length=function(e){return this._isObject(e)?Object.keys(e).length:"number"==typeof e.length?e.length:0},this._isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this._options=function(e,t,i){var a=e.data("flexdatalist");if(n._isDefined(t)){if(n._isDefined(i))a[t]=i;else{if(!n._isObject(t))return n._isDefined(a,t)?a[t]:null;a=t}a.searchIn=n._csvToArray(a.searchIn),a.relatives=a.relatives&&$(a.relatives).length>0?$(a.relatives):null,a.textProperty=null===a.textProperty?a.searchIn[0]:a.textProperty,a.visibleProperties=n._csvToArray(a.visibleProperties,a.searchIn),e.data("flexdatalist",a)}return a},"string"==typeof e)if("function"==typeof this["_"+e]){if(!this["_"+e]())return this}else{if("value"!==e)return t?(n._options(s,e,t),this):n._options(s.data("flexdatalist"),e);this._setValue(t)}return this.each(i)};var _defaultValFunc=jQuery.fn.val;jQuery.fn.val=function(e,t){return!t&&$(this).hasClass("flexdatalist-set")&&"undefined"!=typeof e&&$(this).flexdatalist("value",e),_defaultValFunc.apply(this,arguments)},$(function(){$("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()});
//# sourceMappingURL=jquery.flexdatalist.min.js.map
<MSG> add value to multiple input with "enter" key press

<DFF> @@ -1,1 +1,1 @@
-jQuery.fn.flexdatalist=function(e,t){"use strict";var i,a=$(document),s=$(this),n=this;if(i=function(){var t,i,a=$(this),s={},l="",r=null;a.attr("name");a.hasClass("flexdatalist-set")&&n._destroy(a),n._options(a,$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"],searchContain:!1,searchEqual:!1,searchDisabled:!1,normalizeString:null,multiple:a.attr("multiple"),maxShownResults:100,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,_values:[]},a.data(),"object"==typeof e?e:{})),a._options=function(e,t){return n._options(a,e,t)},a._init=function(){var e=a._options();t=a.clone(!1).attr({list:null,name:null,id:a.attr("id")?a.attr("id")+"-flexdatalist":null}).addClass("flexdatalist-alias").removeClass("flexdatalist"),a._options("multiple")?(i=$("<ul>").addClass("flexdatalist-multiple").css({"border-color":a.css("border-left-color"),"border-width":a.css("border-left-width"),"border-style":a.css("border-left-style"),"border-radius":a.css("border-top-left-radius")}).insertAfter(a).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(i)):t.insertAfter(a),t.attr("autofocus")&&t.focus(),t.on("input keydown",function(i){var s=a._keyword();188===n._keyNum(i)&&!e.selectionRequired&&e.multiple?(i.preventDefault(),a._value(s),a._removeResults()):9===n._keyNum(i)?a._removeResults():0===s.length&&e.multiple&&8===n._keyNum(i)&&t.data("_remove",t.parents("li:eq(0)").prev())}).on("input keyup",function(i){if(a._changed()&&13!==n._keyNum(i)){var s=a._keyword();s.length>=e.minLength?a._search(function(e){a._showResults(e)}):a._removeResults(),e.multiple||(e.selectionRequired?a._value(""):a._value(s))}var r=t.data("_remove");r&&(r.find(".fdl-remove").click(),t.data("_remove",null)),l=a._keyword()}).focus(function(){var t=a._keyword();0===e.minLength?""===t&&a._tdata(function(e){a._showResults(e)}):t.length>=e.minLength&&!a._selected()&&a._search(function(e){a._showResults(e)})}).attr("autocomplete","off"),window.onresize=function(){a._position()},a.addClass("flexdatalist flexdatalist-set").attr("type","hidden")},a._changed=function(){return l!==a._keyword()},a._chained=function(){var e=a._options();if(e.relatives&&e.chainedRelatives){var l=function(s){e.relatives.each(function(){var l=n._isEmpty($(this).val()),r=n._isEmpty(a.val());t.prop("disabled",l),s||!l&&r||(a._value(""),t.val(""),e.multiple&&i.find("li .remove").click()),i&&(l&&i?i.addClass("disabled"):i.removeClass("disabled"))})};e.relatives.on("change",function(){l(),s={}}),l(!0)}},a._initValue=function(){var e=a.attr("value");n._isEmpty(e)||(a._options("originalValue",a.val()),a._parseValue(e,function(e){a.val("",!0),t.val(""),n._isEmpty(e)||a._values(e),l=a._keyword()}))},a._parseValue=function(e,t){var i=a._options();if(a._toJSON())try{t(JSON.parse(e))}catch(s){}else if(a._toCSV()||"string"==typeof i.valueProperty){var n=e.split(",");if("string"==typeof i.valueProperty){var l=i.searchIn;i.searchIn=i.valueProperty.split(","),i.searchEqual=!0,a._search(function(e){e.length>0&&t(e),i.searchIn=l,i.searchEqual=!1},n)}else t(n)}else t(e)},a._tdata=function(e){a.trigger("before:flexdatalist.data"),a._url(function(t){a._data(function(i){i=i.concat(t);for(var s=a._options("_values"),n=0;n<i.length;n++){var l=i[n];s&&s.indexOf(a._getText(l))>-1&&delete i[n]}a.trigger("after:flexdatalist.data",[i]),e(i)})})},a._data=function(e){var t=a._options();"string"==typeof t.data?a._remote({url:t.data,success:function(i){var s=a._getRemoteData(i);t.data=s,e(s)}}):e(t.data)},a._url=function(e){var t=a._options(),i=a._keyword(),s=a.val(),l=i;return n._isEmpty(t.url)?e([]):(clearTimeout(r),void(r=setTimeout(function(){t.cache&&2!==t.cache&&(l=i.substring(0,t.minLength>0?t.minLength:1));var n=a._cache(l);return n?void e(n):(delete t.relatives,delete t._values,void a._remote({url:t.url,data:$.extend(a._relativesData(),t.params,{keyword:i,contain:t.searchContain,selected:s,options:t}),success:function(t){var s=a._getRemoteData(t),n=a._keyword();n.length>i.length?a._search(function(e){a._showResults(e)}):e(s),a._cache(l,s)}}))},200)))},a._remote=function(e){a.hasClass("flexdatalist-loading")||(a.addClass("flexdatalist-loading"),e=$.extend({type:"post",dataType:"json",complete:function(){a.removeClass("flexdatalist-loading")}},e),$.ajax(e))},a._getRemoteData=function(e){var t=e.results?e.results:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t.options&&n._options(a,t.options),n._isObject(t)?t:[]},a._relativesData=function(){var e=a._options("relatives"),t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t},a._datalist=function(){var e=a._options(),t=a.attr("list");return n._isEmpty(t)||(e.data=[],$("#"+t).find("option").each(function(){var t=$(this),i=t.val(),a=t.text();e.data.push({label:a.length>0?a:i,value:i})})),a},a._cache=function(e,t){if(a._options("cache")){if(e=a._normalizeString(e),!n._isDefined(t))return n._isDefined(s,e)&&(t=s[e]),t;s[e]=t}return null},a._search=function(e,t){a._tdata(function(i){var s=[],l=a._options();if(l.searchDisabled)return e(i);n._isDefined(t)||(t=a._keyword()),"string"==typeof t&&(t=[t]),a.trigger("before:flexdatalist.search",[t,i]);for(var r=0;r<t.length;r++)for(var o=t[r],u=0;u<i.length;u++){var d=a._matches(i[u],o,l.values);d&&s.push(d)}a.trigger("after:flexdatalist.search",[t,i,s]),e(s)})},a._matches=function(e,t){for(var i=!1,s=$.extend({},e),l=a._options(),r=l.searchIn,o=0;o<r.length;o++){var u=r[o];if(n._isDefined(e,u)&&e[u]){var d=e[u].toString();a._find(t,d)&&(s[u+"_highlight"]=a._highlight(t,d),i=!0)}}return i?s:null},a._highlight=function(e,t){return t.replace(new RegExp(e,a._options("searchContain")?"ig":"i"),'<span class="highlight">$&</span>')},a._find=function(e,t){var i=a._options();return t=a._normalizeString(t),e=a._normalizeString(e),i.searchEqual?t==e:i.searchContain?t.indexOf(e)>=0:0===t.indexOf(e)},a._showResults=function(e){a._removeResults(!0);var t=a._options();if(0===e.length)return void a._noResults(t.noResultsText);var i=a._getResultsContainer();t.groupBy?(e=a._groupData(e),Object.keys(e).forEach(function(s){var n=e[s],l=t.groupBy,r=a._getHighlight(n[0],l,s);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(r)).append($("<span>").addClass("group-item-count").text(" "+n.length)).appendTo(i);a._items(n,i)})):a._items(e,i);var s=i.find("li:not(.group)");s.on("click",function(){var e=$(this).data("item");e&&(a._selected(!0)._removeResults()._value(e),a.trigger("select:flexdatalist",[e,t]))}).hover(function(){s.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),t.focusFirstResult&&s.filter(":first").addClass("active")},a._noResults=function(e){if(!n._isEmpty(e)){var t=a._getResultsContainer(),i=a._keyword();e=e.split("{keyword}").join(i),$("<li>").addClass("item no-results").append(e).appendTo(t)}},a._groupData=function(e){for(var t=[],i=a._options("groupBy"),s=0;s<e.length;s++){var l=e[s];if(n._isDefined(l,i)){var r=l[i];n._isDefined(t,r)||(t[r]=[]),t[r].push(l)}}return t},a._items=function(e,t){var i=a._options("maxShownResults");a.trigger("show:flexdatalist.results",[e]);for(var s=0;s<e.length&&!(i>0&&i===s);s++)a._item(e[s]).appendTo(t);a.trigger("shown:flexdatalist.results",[e])},a._item=function(e){for(var t=$("<li>").data("item",e).addClass("item"),i=a._options(),s=i.visibleProperties,l=0;l<s.length;l++){var r=s[l];if((!i.groupBy||i.groupBy!==r)&&n._isDefined(e,r)){var o={};if("thumb"===r)o=$("<img>").addClass("item item-"+r).attr("src",e[r]);else{var u=a._getHighlight(e,r);o=$("<span>").addClass("item item-"+r).html(u+" ")}o.appendTo(t)}}return t},a._getHighlight=function(e,t,i){return n._isDefined(e,t+"_highlight")?e[t+"_highlight"]:n._isDefined(e,t)?e[t]:i},a._getResultsContainer=function(){var e=a;a._options("multiple")&&(e=i);var s=$("ul.flexdatalist-results");return 0===s.length&&(s=$("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":e.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":e.css("border-bottom-left-radius"),"border-bottom-right-radius":e.css("border-bottom-right-radius")}).data("target",t),a._position()),s},a._removeResults=function(e){var t="ul.flexdatalist-results";return e&&(t="ul.flexdatalist-results li"),$(t).remove(),a},a._selected=function(e){var t="flexdatalist-selected";return n._isDefined(e)?(e?a.addClass(t):a.removeClass(t),a):a.hasClass(t)},a._values=function(e){return $.isArray(e)&&!n._isEmpty(e)?void $.each(e,function(e,t){a._value(t)}):void a._value(e)},a._value=function(e){var s=a._options(),n=a._getText(e),r=a._getValue(e);if(n.length>0&&s._values.push(n),s.multiple){if(""===e)return a;t.val("");var o=$("<li>").addClass("value"+(s.toggleSelected?" toggle":"")).append('<span class="text">'+n+"</span>").append('<span class="fdl-remove">&times;</span>').insertBefore(i.find("li.input-container"));o.find("span.fdl-remove").click(function(){var e=$(this).parent(),t=e.index();if(!e.hasClass("disabled")&&(a._toJSON()||a._toCSV())){var i=a._inputValue();i.splice(t,1),s._values.splice(t,1),a._inputValue(i)}e.remove()}),s.toggleSelected&&o.click(function(){var e=$(this),t=a._inputValue(),i=e.index();if(e.hasClass("disabled")){var l=e.data("_value");t.splice(i,0,l),s._values.splice(i,0,a._getText(l)),e.removeClass("disabled")}else{var l=t.splice(i,1);e.data("_value",l[0]),s._values.splice(i,1),e.addClass("disabled")}a._inputValue(t,n)})}else n&&n!==t.val()&&t.val(n);return a._inputValue(r,n),l=a._keyword(),a},a._inputValue=function(e,t){var i=a._toJSON(),s=a._toCSV();return n._isDefined(e)?(n._isObject(e)&&(i&&!n._isEmpty(e)?e=JSON.stringify(e):s&&(e=e.join(","))),""===e&&a._options("_values",[]),a.val(e,!0),a.trigger("change:flexdatalist",[e,t,a._options()]).trigger("change"),e):(e=a.val(),e?i?e=JSON.parse(e):s&&(e=e.split(",")):(i||s)&&(e=[]),e)},a._getText=function(e){var t=e,i=a._options();return n._isObject(e)&&(t=e[i.searchIn[0]],t=n._isDefined(e,i.textProperty)?e[i.textProperty]:a._replacePlaceholders(e,i.textProperty,t)),$("<div>").html(t).text()},a._getValue=function(e){var t=e,i=a._options();if(n._isObject(e))if(t=e[i.searchIn[0]],"*"===i.valueProperty)t=e;else if(n._isDefined(e,i.valueProperty))t=e[i.valueProperty];else if(a._toJSON()){var t={},s=i.valueProperty,l=i.textProperty;if(l){var r=l;"string"==typeof l&&(r=a._parsePlaceholders(l)),n._isObject(r)&&$.each(r,function(e,t){s.push(t)})}else n._isDefined(e,l)&&s.push(l);$.each(s,function(i,a){n._isDefined(e,a)&&(t[a]=e[a])})}if(i.multiple&&(a._toJSON()||a._toCSV())){var o=a._inputValue();!n._isEmpty(t)&&n._isObject(o)&&(o.push(t),t=o)}return t},a._replacePlaceholders=function(e,t,i){if(n._isObject(e)&&"string"==typeof t){var s=a._parsePlaceholders(t);if(!n._isEmpty(e)&&s)return $.each(s,function(i,a){n._isDefined(e,a)&&(t=t.replace(i,e[a]))}),t}return i},a._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var i={};return t.map(function(e){i[e]=e.slice(1,-1)}),i}return!1},a._normalizeString=function(e){if("string"==typeof e){var t=a._options("normalizeString");return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e},a._keyword=function(){return t.val().replace(/^\s+/,"")},a._toJSON=function(){var e=a._options("valueProperty");return n._isObject(e)||"*"===e},a._toCSV=function(){return!a._toJSON()&&a._options("multiple")},a._position=function(){var e=t;a._options("multiple")&&(e=i),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px","z-index":e.css("z-index")+1})},a._init(),a._datalist(),a._initValue(),a._chained()},this._destroy=function(e){e||(e=s),e.each(function(){var e=$(this).data("flexdatalist");$(this).removeClass("flexdatalist-set").attr("type","text").val(e&&e.originalValue?e.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})},this._reset=function(){this._destroy()},this._setValue=function(e){s.each(function(){var t=$(this),i=t.data("flexdatalist");if(i){if(i.originalValue=e,""==e)return t.val(e,!0).trigger("change:flexdatalist",[e,e,i]).trigger("change"),void(i.multiple&&t.next("ul.flexdatalist-multiple").find("li.value").remove());n._destroy()}})},this._keyNum=function(e){return e.which||e.keyCode},a.data("flexdatalist")||$(document).mouseup(function(e){var t=$(".flexdatalist-results"),i=t.data("target");i&&i.is(":focus")||t.is(e.target)||0!==t.has(e.target).length||t.remove()}).keydown(function(e){var t=$(".flexdatalist-results"),i=t.find("li"),a=i.filter(".active"),s=a.index(),l=i.length,r=n._keyNum(e);if(0!==l)if(13===r)e.preventDefault(),a.click();else if(40===r||38===r){e.preventDefault(),40===r?a=l>s&&a.nextAll(".item").first().length>0?a.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===r&&(a=s>0&&a.prevAll(".item").first().length>0?a.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active"));var o=(0===a.prev().length?a:a.prev()).position().top;t.animate({scrollTop:o+t.scrollTop()},100)}}).data("flexdatalist",!0),this._isEmpty=function(e){return n._isDefined(e)?null===e?!0:e===!0?!1:0===this._length(e)?!0:""===$.trim(e):!0},this._isObject=function(e){return e&&"object"==typeof e},this._csvToArray=function(e,t){return 0===e.length?t:"string"==typeof e?e.split(","):e},this._length=function(e){return this._isObject(e)?Object.keys(e).length:"number"==typeof e.length?e.length:0},this._isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this._options=function(e,t,i){var a=e.data("flexdatalist");if(n._isDefined(t)){if(n._isDefined(i))a[t]=i;else{if(!n._isObject(t))return n._isDefined(a,t)?a[t]:null;a=t}a.searchIn=n._csvToArray(a.searchIn),a.relatives=a.relatives&&$(a.relatives).length>0?$(a.relatives):null,a.textProperty=null===a.textProperty?a.searchIn[0]:a.textProperty,a.visibleProperties=n._csvToArray(a.visibleProperties,a.searchIn),e.data("flexdatalist",a)}return a},"string"==typeof e)if("function"==typeof this["_"+e]){if(!this["_"+e]())return this}else{if("value"!==e)return t?(n._options(s,e,t),this):n._options(s.data("flexdatalist"),e);this._setValue(t)}return this.each(i)};var _defaultValFunc=jQuery.fn.val;jQuery.fn.val=function(e,t){return!t&&$(this).hasClass("flexdatalist-set")&&"undefined"!=typeof e&&$(this).flexdatalist("value",e),_defaultValFunc.apply(this,arguments)},$(function(){$("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()});
\ No newline at end of file
+jQuery.fn.flexdatalist=function(e,t){"use strict";var i,a=$(document),s=$(this),n=this;if(i=function(){var t,i,a=$(this),s={},l="",r=null;a.attr("name");a.hasClass("flexdatalist-set")&&n._destroy(a),n._options(a,$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],searchIn:["label"],searchContain:!1,searchEqual:!1,searchDisabled:!1,normalizeString:null,multiple:a.attr("multiple"),maxShownResults:100,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,_values:[]},a.data(),"object"==typeof e?e:{})),a._options=function(e,t){return n._options(a,e,t)},a._init=function(){var e=a._options();t=a.clone(!1).attr({list:null,name:null,id:a.attr("id")?a.attr("id")+"-flexdatalist":null}).addClass("flexdatalist-alias").removeClass("flexdatalist"),a._options("multiple")?(i=$("<ul>").addClass("flexdatalist-multiple").css({"border-color":a.css("border-left-color"),"border-width":a.css("border-left-width"),"border-style":a.css("border-left-style"),"border-radius":a.css("border-top-left-radius")}).insertAfter(a).click(function(){$(this).find("input").focus()}),$('<li class="input-container">').addClass("flexdatalist-multiple-value").append(t).appendTo(i)):t.insertAfter(a),t.attr("autofocus")&&t.focus(),t.on("input keydown",function(i){var s=a._keyword();188!==n._keyNum(i)&&13!==n._keyNum(i)||e.selectionRequired||!e.multiple?9===n._keyNum(i)?a._removeResults():0===s.length&&e.multiple&&8===n._keyNum(i)&&t.data("_remove",t.parents("li:eq(0)").prev()):(i.preventDefault(),a._value(s),a._removeResults())}).on("input keyup",function(i){if(a._changed()&&13!==n._keyNum(i)){var s=a._keyword();s.length>=e.minLength?a._search(function(e){a._showResults(e)}):a._removeResults(),e.multiple||(e.selectionRequired?a._value(""):a._value(s))}var r=t.data("_remove");r&&(r.find(".fdl-remove").click(),t.data("_remove",null)),l=a._keyword()}).focus(function(){var t=a._keyword();0===e.minLength?""===t&&a._tdata(function(e){a._showResults(e)}):t.length>=e.minLength&&!a._selected()&&a._search(function(e){a._showResults(e)})}).attr("autocomplete","off"),window.onresize=function(){a._position()},a.addClass("flexdatalist flexdatalist-set").attr("type","hidden")},a._changed=function(){return l!==a._keyword()},a._chained=function(){var e=a._options();if(e.relatives&&e.chainedRelatives){var l=function(s){e.relatives.each(function(){var l=n._isEmpty($(this).val()),r=n._isEmpty(a.val());t.prop("disabled",l),s||!l&&r||(a._value(""),t.val(""),e.multiple&&i.find("li .fdl-remove").click()),i&&(l&&i?i.addClass("disabled"):i.removeClass("disabled"))})};e.relatives.on("change",function(){l(),s={}}),l(!0)}},a._initValue=function(){var e=a.attr("value");n._isEmpty(e)||(a._options("originalValue",a.val()),a._parseValue(e,function(e){a.val("",!0),t.val(""),n._isEmpty(e)||a._values(e),l=a._keyword()}))},a._parseValue=function(e,t){var i=a._options();if(a._toJSON())try{t(JSON.parse(e))}catch(s){}else if(a._toCSV()||"string"==typeof i.valueProperty){var n=e.split(",");if("string"==typeof i.valueProperty){var l=i.searchIn;i.searchIn=i.valueProperty.split(","),i.searchEqual=!0,a._search(function(e){e.length>0&&t(e),i.searchIn=l,i.searchEqual=!1},n)}else t(n)}else t(e)},a._tdata=function(e){a.trigger("before:flexdatalist.data"),a._url(function(t){a._data(function(i){i=i.concat(t);for(var s=a._options("_values"),n=0;n<i.length;n++){var l=i[n];s&&s.indexOf(a._getText(l))>-1&&delete i[n]}a.trigger("after:flexdatalist.data",[i]),e(i)})})},a._data=function(e){var t=a._options();"string"==typeof t.data?a._remote({url:t.data,success:function(i){var s=a._getRemoteData(i);t.data=s,e(s)}}):e(t.data)},a._url=function(e){var t=a._options(),i=a._keyword(),s=a.val(),l=i;return n._isEmpty(t.url)?e([]):(clearTimeout(r),void(r=setTimeout(function(){t.cache&&2!==t.cache&&(l=i.substring(0,t.minLength>0?t.minLength:1));var n=a._cache(l);if(n)return void e(n);var r={};$.each(t,function(e,t){0!=e.indexOf("_")&&(r[e]=t)}),delete r.relatives,a._remote({url:t.url,data:$.extend(a._relativesData(),t.params,{keyword:i,contain:t.searchContain,selected:s,options:r}),success:function(t){var s=a._getRemoteData(t),n=a._keyword();n.length>i.length?a._search(function(e){a._showResults(e)}):e(s),a._cache(l,s)}})},200)))},a._remote=function(e){a.hasClass("flexdatalist-loading")||(a.addClass("flexdatalist-loading"),e=$.extend({type:"post",dataType:"json",complete:function(){a.removeClass("flexdatalist-loading")}},e),$.ajax(e))},a._getRemoteData=function(e){var t=e.results?e.results:e;return"string"==typeof t&&0===t.indexOf("[{")&&(t=JSON.parse(t)),t.options&&n._options(a,t.options),n._isObject(t)?t:[]},a._relativesData=function(){var e=a._options("relatives"),t={};return e&&(t.relatives={},e.each(function(){var e=$(this),i=e.attr("name").split("][").join("-").split("]").join("-").split("[").join("-").replace(/^\|+|\-+$/g,"");t.relatives[i]=e.val()})),t},a._datalist=function(){var e=a._options(),t=a.attr("list");return n._isEmpty(t)||(e.data=[],$("#"+t).find("option").each(function(){var t=$(this),i=t.val(),a=t.text();e.data.push({label:a.length>0?a:i,value:i})})),a},a._cache=function(e,t){if(a._options("cache")){if(e=a._normalizeString(e),!n._isDefined(t))return n._isDefined(s,e)&&(t=s[e]),t;s[e]=t}return null},a._search=function(e,t){a._tdata(function(i){var s=[],l=a._options();if(l.searchDisabled)return e(i);n._isDefined(t)||(t=a._keyword()),"string"==typeof t&&(t=[t]),a.trigger("before:flexdatalist.search",[t,i]);for(var r=0;r<t.length;r++)for(var o=t[r],u=0;u<i.length;u++){var d=a._matches(i[u],o,l.values);d&&s.push(d)}a.trigger("after:flexdatalist.search",[t,i,s]),e(s)})},a._matches=function(e,t){for(var i=!1,s=$.extend({},e),l=a._options(),r=l.searchIn,o=0;o<r.length;o++){var u=r[o];if(n._isDefined(e,u)&&e[u]){var d=e[u].toString();a._find(t,d)&&(s[u+"_highlight"]=a._highlight(t,d),i=!0)}}return i?s:null},a._highlight=function(e,t){return t.replace(new RegExp(e,a._options("searchContain")?"ig":"i"),'<span class="highlight">$&</span>')},a._find=function(e,t){var i=a._options();return t=a._normalizeString(t),e=a._normalizeString(e),i.searchEqual?t==e:i.searchContain?t.indexOf(e)>=0:0===t.indexOf(e)},a._showResults=function(e){a._removeResults(!0);var t=a._options();if(0===e.length)return void a._noResults(t.noResultsText);var i=a._getResultsContainer();t.groupBy?(e=a._groupData(e),Object.keys(e).forEach(function(s){var n=e[s],l=t.groupBy,r=a._getHighlight(n[0],l,s);$("<li>").addClass("group").append($("<span>").addClass("group-name").html(r)).append($("<span>").addClass("group-item-count").text(" "+n.length)).appendTo(i);a._items(n,i)})):a._items(e,i);var s=i.find("li:not(.group)");s.on("click",function(){var e=$(this).data("item");e&&(a._selected(!0)._removeResults()._value(e),a.trigger("select:flexdatalist",[e,t]))}).hover(function(){s.removeClass("active"),$(this).addClass("active")},function(){$(this).removeClass("active")}),t.focusFirstResult&&s.filter(":first").addClass("active")},a._noResults=function(e){if(!n._isEmpty(e)){var t=a._getResultsContainer(),i=a._keyword();e=e.split("{keyword}").join(i),$("<li>").addClass("item no-results").append(e).appendTo(t)}},a._groupData=function(e){for(var t=[],i=a._options("groupBy"),s=0;s<e.length;s++){var l=e[s];if(n._isDefined(l,i)){var r=l[i];n._isDefined(t,r)||(t[r]=[]),t[r].push(l)}}return t},a._items=function(e,t){var i=a._options("maxShownResults");a.trigger("show:flexdatalist.results",[e]);for(var s=0;s<e.length&&!(i>0&&i===s);s++)a._item(e[s]).appendTo(t);a.trigger("shown:flexdatalist.results",[e])},a._item=function(e){for(var t=$("<li>").data("item",e).addClass("item"),i=a._options(),s=i.visibleProperties,l=0;l<s.length;l++){var r=s[l];if((!i.groupBy||i.groupBy!==r)&&n._isDefined(e,r)){var o={};if("thumb"===r)o=$("<img>").addClass("item item-"+r).attr("src",e[r]);else{var u=a._getHighlight(e,r);o=$("<span>").addClass("item item-"+r).html(u+" ")}o.appendTo(t)}}return t},a._getHighlight=function(e,t,i){return n._isDefined(e,t+"_highlight")?e[t+"_highlight"]:n._isDefined(e,t)?e[t]:i},a._getResultsContainer=function(){var e=a;a._options("multiple")&&(e=i);var s=$("ul.flexdatalist-results");return 0===s.length&&(s=$("<ul>").addClass("flexdatalist-results").appendTo("body").css({"border-color":e.css("border-left-color"),"border-width":"1px","border-bottom-left-radius":e.css("border-bottom-left-radius"),"border-bottom-right-radius":e.css("border-bottom-right-radius")}).data("target",t),a._position()),s},a._removeResults=function(e){var t="ul.flexdatalist-results";return e&&(t="ul.flexdatalist-results li"),$(t).remove(),a},a._selected=function(e){var t="flexdatalist-selected";return n._isDefined(e)?(e?a.addClass(t):a.removeClass(t),a):a.hasClass(t)},a._values=function(e){return $.isArray(e)&&!n._isEmpty(e)?void $.each(e,function(e,t){a._value(t)}):void a._value(e)},a._value=function(e){var s=a._options(),n=a._getText(e),r=a._getValue(e);if(n.length>0&&s._values.push(n),s.multiple){if(""===e)return a;t.val("");var o=$("<li>").addClass("value"+(s.toggleSelected?" toggle":"")).append('<span class="text">'+n+"</span>").append('<span class="fdl-remove">&times;</span>').insertBefore(i.find("li.input-container"));o.find("span.fdl-remove").click(function(){var e=$(this).parent(),t=e.index();if(!e.hasClass("disabled")&&(a._toJSON()||a._toCSV())){var i=a._inputValue();i.splice(t,1),s._values.splice(t,1),a._inputValue(i)}e.remove()}),s.toggleSelected&&o.click(function(){var e=$(this),t=a._inputValue(),i=e.index();if(e.hasClass("disabled")){var l=e.data("_value");t.splice(i,0,l),s._values.splice(i,0,a._getText(l)),e.removeClass("disabled")}else{var l=t.splice(i,1);e.data("_value",l[0]),s._values.splice(i,1),e.addClass("disabled")}a._inputValue(t,n)})}else n&&n!==t.val()&&t.val(n);return a._inputValue(r,n),l=a._keyword(),a},a._inputValue=function(e,t){var i=a._toJSON(),s=a._toCSV();return n._isDefined(e)?(n._isObject(e)&&(i&&!n._isEmpty(e)?e=JSON.stringify(e):s&&(e=e.join(","))),""===e&&a._options("_values",[]),a.val(e,!0),a.trigger("change:flexdatalist",[e,t,a._options()]).trigger("change"),e):(e=a.val(),e?i?e=JSON.parse(e):s&&(e=e.split(",")):(i||s)&&(e=[]),e)},a._getText=function(e){var t=e,i=a._options();return n._isObject(e)&&(t=e[i.searchIn[0]],t=n._isDefined(e,i.textProperty)?e[i.textProperty]:a._replacePlaceholders(e,i.textProperty,t)),$("<div>").html(t).text()},a._getValue=function(e){var t=e,i=a._options();if(n._isObject(e))if(t=e[i.searchIn[0]],"*"===i.valueProperty)t=e;else if(n._isDefined(e,i.valueProperty))t=e[i.valueProperty];else if(a._toJSON()){var t={},s=i.valueProperty,l=i.textProperty;if(l){var r=l;"string"==typeof l&&(r=a._parsePlaceholders(l)),n._isObject(r)&&$.each(r,function(e,t){s.push(t)})}else n._isDefined(e,l)&&s.push(l);$.each(s,function(i,a){n._isDefined(e,a)&&(t[a]=e[a])})}if(i.multiple&&(a._toJSON()||a._toCSV())){var o=a._inputValue();!n._isEmpty(t)&&n._isObject(o)&&(o.push(t),t=o)}return t},a._replacePlaceholders=function(e,t,i){if(n._isObject(e)&&"string"==typeof t){var s=a._parsePlaceholders(t);if(!n._isEmpty(e)&&s)return $.each(s,function(i,a){n._isDefined(e,a)&&(t=t.replace(i,e[a]))}),t}return i},a._parsePlaceholders=function(e){var t=e.match(/\{.+?\}/g);if(t){var i={};return t.map(function(e){i[e]=e.slice(1,-1)}),i}return!1},a._normalizeString=function(e){if("string"==typeof e){var t=a._options("normalizeString");return"function"==typeof t&&(e=t(e)),e.toUpperCase()}return e},a._keyword=function(){return t.val().replace(/^\s+/,"")},a._toJSON=function(){var e=a._options("valueProperty");return n._isObject(e)||"*"===e},a._toCSV=function(){return!a._toJSON()&&a._options("multiple")},a._position=function(){var e=t;a._options("multiple")&&(e=i),$("ul.flexdatalist-results").css({width:e.outerWidth()+"px",top:e.offset().top+e.outerHeight()+"px",left:e.offset().left+"px","z-index":e.css("z-index")+1})},a._init(),a._datalist(),a._initValue(),a._chained()},this._destroy=function(e){e||(e=s),e.each(function(){var e=$(this).data("flexdatalist");$(this).removeClass("flexdatalist-set").attr("type","text").val(e&&e.originalValue?e.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})},this._reset=function(){this._destroy()},this._setValue=function(e){s.each(function(){var t=$(this),i=t.data("flexdatalist");if(i){if(i.originalValue=e,""==e)return t.val(e,!0).trigger("change:flexdatalist",[e,e,i]).trigger("change"),void(i.multiple&&t.next("ul.flexdatalist-multiple").find("li.value").remove());n._destroy()}})},this._keyNum=function(e){return e.which||e.keyCode},a.data("flexdatalist")||$(document).mouseup(function(e){var t=$(".flexdatalist-results"),i=t.data("target");i&&i.is(":focus")||t.is(e.target)||0!==t.has(e.target).length||t.remove()}).keydown(function(e){var t=$(".flexdatalist-results"),i=t.find("li"),a=i.filter(".active"),s=a.index(),l=i.length,r=n._keyNum(e);if(0!==l)if(13===r)e.preventDefault(),a.click();else if(40===r||38===r){e.preventDefault(),40===r?a=l>s&&a.nextAll(".item").first().length>0?a.removeClass("active").nextAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:first").addClass("active"):38===r&&(a=s>0&&a.prevAll(".item").first().length>0?a.removeClass("active").prevAll(".item").first().addClass("active"):i.removeClass("active").filter(".item:last").addClass("active"));var o=(0===a.prev().length?a:a.prev()).position().top;t.animate({scrollTop:o+t.scrollTop()},100)}}).data("flexdatalist",!0),this._isEmpty=function(e){return n._isDefined(e)?null===e?!0:e===!0?!1:0===this._length(e)?!0:""===$.trim(e):!0},this._isObject=function(e){return e&&"object"==typeof e},this._csvToArray=function(e,t){return 0===e.length?t:"string"==typeof e?e.split(","):e},this._length=function(e){return this._isObject(e)?Object.keys(e).length:"number"==typeof e.length?e.length:0},this._isDefined=function(e,t){var i="undefined"!=typeof e;return i&&"undefined"!=typeof t?"undefined"!=typeof e[t]:i},this._options=function(e,t,i){var a=e.data("flexdatalist");if(n._isDefined(t)){if(n._isDefined(i))a[t]=i;else{if(!n._isObject(t))return n._isDefined(a,t)?a[t]:null;a=t}a.searchIn=n._csvToArray(a.searchIn),a.relatives=a.relatives&&$(a.relatives).length>0?$(a.relatives):null,a.textProperty=null===a.textProperty?a.searchIn[0]:a.textProperty,a.visibleProperties=n._csvToArray(a.visibleProperties,a.searchIn),e.data("flexdatalist",a)}return a},"string"==typeof e)if("function"==typeof this["_"+e]){if(!this["_"+e]())return this}else{if("value"!==e)return t?(n._options(s,e,t),this):n._options(s.data("flexdatalist"),e);this._setValue(t)}return this.each(i)};var _defaultValFunc=jQuery.fn.val;jQuery.fn.val=function(e,t){return!t&&$(this).hasClass("flexdatalist-set")&&"undefined"!=typeof e&&$(this).flexdatalist("value",e),_defaultValFunc.apply(this,arguments)},$(function(){$("input.flexdatalist:not(.flexdatalist-set)").flexdatalist()});
\ No newline at end of file

add value to multiple input with "enter" key press