From 5c79b4aeecd86f8e9476e728c6602cd8d24a0937 Mon Sep 17 00:00:00 2001 From: Sergio Dinis Lopes Date: Sat, 9 Sep 2017 23:06:27 +0100 Subject: [PATCH] placeholder fix minor improvements --- jquery.flexdatalist.js | 10 ++++++---- jquery.flexdatalist.min.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jquery.flexdatalist.js b/jquery.flexdatalist.js index 7320954..4206c46 100644 --- a/jquery.flexdatalist.js +++ b/jquery.flexdatalist.js @@ -3,7 +3,7 @@ * Autocomplete input fields, with support for datalists. * * Version: - * 2.2.1 + * 2.2.2 * * Depends: * jquery.js > 1.8.3 @@ -31,7 +31,8 @@ jQuery.fn.flexdatalist = function (_option, _value) { .attr('style', null) .val((options && options.originalValue && !clear ? options.originalValue : '')) .removeData('flexdatalist') - .removeData('aliascontainer'); + .removeData('aliascontainer') + .off(); $aliascontainer.remove(); } }); @@ -259,8 +260,9 @@ jQuery.fn.flexdatalist = function (_option, _value) { copyValue: function (event) { if (_this.keyNum(event) !== 13) { var keyword = $alias.val(), + val = _this.fvalue.get(true), options = _this.options.get(); - if (!options.multiple && !options.selectionRequired) { + if (!options.multiple && !options.selectionRequired && keyword.length !== val.length) { _this.fvalue.extract(keyword); } } @@ -388,7 +390,7 @@ jQuery.fn.flexdatalist = function (_option, _value) { 'class': $this.attr('class'), 'name': ($this.attr('name') ? 'flexdatalist-' + $this.attr('name') : null), 'id': aliasid, - 'value': '' + 'placeholder': $this.attr('placeholder') }) .addClass('flexdatalist-alias ' + aliasid) .removeClass('flexdatalist') diff --git a/jquery.flexdatalist.min.js b/jquery.flexdatalist.min.js index edb8eac..bb29282 100644 --- a/jquery.flexdatalist.min.js +++ b/jquery.flexdatalist.min.js @@ -1,2 +1,2 @@ -/** jQuery.Flexdatalist 2.2.1 */ -jQuery.fn.flexdatalist=function(e,t){"use strict";var i=function(e,t){e.each(function(){var e=$(this),i=e.data(),a=i.flexdatalist,r=i.aliascontainer;r&&(e.removeClass("flexdatalist-set").attr("style",null).val(a&&a.originalValue&&!t?a.originalValue:"").removeData("flexdatalist").removeData("aliascontainer"),r.remove())})};if("string"==typeof e&&"reset"!==e){if("undefined"!=typeof this[0].fvalue){var a=this[0];if("destroy"===e)i(this,t);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("disabled"===e){if("undefined"==typeof t)return a.fdisabled();a.fdisabled(t)}else if("string"==typeof e){if("undefined"==typeof t)return a.options.get(e);a.options.set(e,t)}return this}e={_option:t}}this.length>0&&"undefined"!=typeof this[0].fvalue&&i(this);var r=$.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,disabled:null,maxShownResults:100,removeOnBackspace:!0,noResultsText:'No results found for "{keyword}"',toggleSelected:!1,allowDuplicateValues:!1,redoSearchOnFocus:!0,requestType:"get",requestContentType:"x-www-form-urlencoded",resultsProperty:"results",keywordParamName:"keyword",limitOfValues:0,valuesSeparator:",",debug:!0},e);return this.each(function(e){var t=$(this),i=this,a=null,n=[],s="flex"+e,l=null,o=null;this.init=function(){var e=this.options.init();this.set.up(),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),i.action.showAllResults(e),i.action.clearValue(e),i.action.removeResults(e),i.action.inputWidth(e)}).on("focusout",function(e){o&&o.removeClass("focus"),i.action.clearText(e),i.action.clearValue(e)}),window.onresize=function(){i.position()},this.cache.gc(),e.selectionRequired&&i.fvalue.clear(!0,!0),this.fvalue._load(e.originalValue,function(){i.fdisabled(e.disabled),t.trigger("init:flexdatalist",[e])},!0)},this.action={keypressValue:function(e,t){var a=i.keyNum(e),r=l[0].value,n=i.options.get();if(r.length>0&&a===t&&!n.selectionRequired&&n.multiple){var r=l[0].value;e.preventDefault(),i.fvalue.extract(r),i.results.remove()}},keypressSearch:function(e){var t=i.keyNum(e),r=l.val(),n=r.length,s=i.options.get();clearTimeout(a),(!t||13!==t&&(37>t||t>40))&&(a=setTimeout(function(){(0===s.minLength&&n>0||s.minLength>0&&n>=s.minLength)&&i.data.load(function(e){i.search.get(r,e,function(e){i.results.show(e)})})},s.searchDelay))},redoSearchFocus:function(e){var t=i.fvalue.get(),a=i.options.get(),r=l.val();a.redoSearchOnFocus&&(r.length>0&&a.multiple||r.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.extract(t)}},backSpaceKeyRemove:function(e){var t=i.options.get();if(t.removeOnBackspace&&t.multiple){var a=l.val(),r=l.data("_remove");8===i.keyNum(e)&&(0===a.length?r?(i.fvalue.remove(r),l.data("_remove",null)):(console.log("remove!"),l.data("_remove",l.parents("li:eq(0)").prev())):l.data("_remove",null))}},showAllResults:function(){var e=l.val();e=$.trim(e),""===e&&0===i.options.get("minLength")&&i.data.load(function(e){i.results.show(e)})},inputWidth:function(){var e=i.options.get();if(e.multiple){var a=l.val(),r=parseInt(l.css("fontSize").replace("px","")),n=40,s=t.innerWidth(),o=(a.length+1)*r;o>=n&&s>=o&&(l[0].style.width=o+"px")}},clearText:function(){var e=i.fvalue.get(),t=i.options.get();!t.multiple&&t.selectionRequired&&0===e.length&&(l[0].value="")},clearValue:function(){var e=(i.fvalue.get(),l.val()),t=i.options.get();!t.multiple&&e.length<=t.minLength&&i.fvalue.clear()},removeResults:function(){var e=(i.fvalue.get(),l.val()),t=i.options.get();t.minLength>0&&e.length').attr({"class":t.attr("class"),name:t.attr("name")?"flexdatalist-"+t.attr("name"):null,id:e,value:""}).addClass("flexdatalist-alias "+e).removeClass("flexdatalist").attr("autocomplete","off");return i},multipleInput:function(e){return o=$('