diff --git a/jquery.flexdatalist.js b/jquery.flexdatalist.js index f404565..290f23f 100644 --- a/jquery.flexdatalist.js +++ b/jquery.flexdatalist.js @@ -742,11 +742,12 @@ jQuery.fn.flexdatalist = function (_option, _value) { */ toObj: function (val) { if (typeof val !== 'object') { + var options = _this.options.get(); if (this.isCSV()) { if (_this.isEmpty(val) || !_this.isDefined(val)) { val = []; } else { - val = val.toString().split(_this.options.get('valuesSeparator')); + val = val.toString().split(options.valuesSeparator); val = $.map(val, function (v) { return $.trim(v); }); diff --git a/jquery.flexdatalist.min.js b/jquery.flexdatalist.min.js index ba5a8b6..be98a94 100644 --- a/jquery.flexdatalist.min.js +++ b/jquery.flexdatalist.min.js @@ -1 +1 @@ -jQuery.fn.flexdatalist=function(e,t){"use strict";var i=function(e){e.each(function(){var e=$(this),t=e.data("flexdatalist");e.removeClass("flexdatalist-set").attr("type","text").val(t&&t.originalValue?t.originalValue:"").removeData("flexdatalist").next(".flexdatalist-alias, ul.flexdatalist-multiple").remove()})};if("string"==typeof e&&"reset"!==e){var a=this[0];if("destroy"===e)i($(this));else if("value"===e){if("undefined"==typeof t)return a.fvalue.get();a.fvalue.set(t)}else if("add"===e){if("undefined"==typeof t)return a.debug("Missing value to add!");a.fvalue.add(t)}else if("toggle"===e){if("undefined"==typeof t)return a.debug("Missing value to toggle!");a.fvalue.toggle(t)}else if("remove"===e){if("undefined"==typeof t)return a.debug("Missing value to remove!");a.fvalue.remove(t)}else if("string"==typeof e){if("undefined"==typeof t)return a.options.get(e);a.options.set(e,t)}return this}this&&"undefined"!=typeof this[0]&&"undefined"!=typeof this[0].fvalue&&i($(this));var n=$.extend({url:null,data:[],params:{},relatives:null,chainedRelatives:!1,cache:!0,cacheLifetime:60,minLength:2,groupBy:!1,selectionRequired:!1,focusFirstResult:!1,textProperty:null,valueProperty:null,visibleProperties:[],iconProperty:"thumb",searchIn:["label"],searchContain:!1,searchEqual:!1,searchByWord:!1,searchDisabled:!1,searchDelay:300,normalizeString:null,multiple:null,maxShownResults:100,removeOnBackspace:!0,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,requestType:"get",requestContentType:"default",resultsProperty:"results",keywordParamName:"keyword",limitOfValues:0,valuesSeparator:",",debug:!0},e);return this.each(function(e){var t=$(this),i=this,a=null,r=[],s="flex"+e,l=null,o=null;this.init=function(){this.options.init(),this.set.up(),this.fvalue.set(t.attr("value")),l.on("focusin",function(e){i.action.redoSearchFocus(e),i.action.showAllResults(e),o&&o.addClass("focus")}).on("input keydown",function(e){9===i.keyNum(e)&&i.results.remove(),i.action.keypressValue(e,188),i.action.backSpaceKeyRemove(e)}).on("input keyup",function(e){i.action.keypressValue(e,13),i.action.keypressSearch(e),i.action.copyValue(e),i.action.backSpaceKeyRemove(e)}).on("focusout",function(){o&&o.removeClass("focus")}),window.onresize=function(){i.position()}},this.action={keypressValue:function(e,t){var a=i.keyNum(e),n=l[0].value,r=i.options.get();if(n.length>0&&a===t&&!r.selectionRequired&&r.multiple){var n=l[0].value;e.preventDefault(),i.fvalue.extract(n),i.results.remove()}},keypressSearch:function(e){var t=i.keyNum(e),n=l.val(),r=n.length,s=i.options.get();clearTimeout(a),0===r&&s.minLength>0||rt||t>40))&&(i.results.remove(),a=setTimeout(function(){0===s.minLength&&r>0||s.minLength>0&&r>=s.minLength?i.search.get(function(e){i.results.show(e)}):i.results.remove()},s.searchDelay))},redoSearchFocus:function(e){var t=i.fvalue.get(),a=i.options.get(),n=l.val();(n.length>0&&a.multiple||n.length>0&&0===t.length)&&this.keypressSearch(e)},copyValue:function(e){if(13!==i.keyNum(e)){var t=l.val(),a=i.options.get();a.multiple||(a.selectionRequired?i.fvalue.clear():i.fvalue.set(t))}},backSpaceKeyRemove:function(e){var t=i.options.get();if(t.removeOnBackspace){var a=l.val(),n=l.data("_remove");n?(n.find(".fdl-remove").click(),l.data("_remove",null)):0===a.length&&t.multiple&&8===i.keyNum(e)&&l.data("_remove",l.parents("li:eq(0)").prev())}},showAllResults:function(){var e=l.val();e=$.trim(e),""===e&&0===i.options.get("minLength")&&i.data.load(function(e){i.results.show(e)})}},this.set={up:function(){l=this.alias(),i.options.get("multiple")?o=this.multipleInput(l):l.insertAfter(t),l.attr("autofocus")&&l.focus(),this.chained()},alias:function(){var e=t.clone(!1).attr({list:null,name:t.attr("name")?"flexdatalist-"+t.attr("name"):null,id:t.attr("id")?t.attr("id")+"-flexdatalist":null,value:""}).addClass("flexdatalist-alias").removeClass("flexdatalist").attr("autocomplete","off");return t.addClass("flexdatalist flexdatalist-set").prop("type","hidden"),e},multipleInput:function(e){return o=$('