diff --git a/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.js b/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.js index 5b6d1450..f238a2de 100644 --- a/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.js +++ b/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.js @@ -23,6 +23,23 @@ function InputfieldTextTags($parent) { } }; + // get the 'render' options for selectize + function getRenderOptions(addLabel) { + return { + item: function(item, escape) { + if(typeof item.label === "undefined" || !item.label.length) item.label = item.value; + return '
' + escape(item.label) + '
'; + }, + option: function(item, escape) { + if(typeof item.label === "undefined" || !item.label.length) item.label = item.value; + return '
' + escape(item.label) + '
'; + }, + option_create: function(data, escape) { + return '
' + addLabel + ' ' + escape(data.input) + '
'; + } + } + } + // initialize input where all tags are input by the user, there are no predefined selectable tags function initInput($input) { var o = JSON.parse($input.attr('data-opts')); @@ -33,6 +50,7 @@ function InputfieldTextTags($parent) { options.persist = false; options.maxItems = (o.maxItems > 0 ? o.maxItems : null); options.plugins = (o.maxItems === 1 ? pluginsSingle : pluginsMulti); + options.render = getRenderOptions(o.addLabel); $input.selectize(options); } @@ -61,7 +79,7 @@ function InputfieldTextTags($parent) { valueField: 'value', labelField: 'label', searchField: [ 'value', 'label' ], - options: tagsList, + 'options': tagsList, createFilter: function(input) { if(o.allowUserTags) return true; var allow = false; @@ -73,16 +91,7 @@ function InputfieldTextTags($parent) { } return allow; }, - render: { - item: function(item, escape) { - if(typeof item.label === "undefined" || !item.label.length) item.label = item.value; - return '
' + escape(item.label) + '
'; - }, - option: function(item, escape) { - if(typeof item.label === "undefined" || !item.label.length) item.label = item.value; - return '
' + escape(item.label) + '
'; - } - } + render: getRenderOptions(o.addLabel) /* onDropdownOpen: function($dropdown) { $dropdown.closest('li, .InputfieldImageEdit').css('z-index', 100); diff --git a/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.min.js b/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.min.js index 88d259da..680b331e 100644 --- a/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.min.js +++ b/wire/modules/Inputfield/InputfieldTextTags/InputfieldTextTags.min.js @@ -1 +1 @@ -function InputfieldTextTags($parent){if(typeof $parent==="undefined")$parent=jQuery(".InputfieldForm");var pluginsMulti=["remove_button","drag_drop"];var pluginsSingle=[];var defaults={delimiter:" ",persist:true,submitOnReturn:false,openOnFocus:true,closeAfterSelect:true,copyClassesToDropdown:false,createOnBlur:false,selectOnTab:true,maxItems:null,create:function(input){return{value:input,text:input}}};function initInput($input){var o=JSON.parse($input.attr("data-opts"));var options=defaults;options.delimiter=o.delimiter;options.closeAfterSelect=o.closeAfterSelect;options.createOnBlur=o.createOnBlur;options.persist=false;options.maxItems=o.maxItems>0?o.maxItems:null;options.plugins=o.maxItems===1?pluginsSingle:pluginsMulti;$input.selectize(options)}function initSelect($select){var o=JSON.parse($select.attr("data-opts"));var cfgName=typeof o.cfgName==="undefined"?"":o.cfgName;var tags=cfgName.length?ProcessWire.config[cfgName]:o.tags;var tagsList=[];var n=0;for(var tag in tags){var label=tags[tag];tagsList[n]={value:tag,label:label};n++}var options=jQuery.extend(defaults,{allowUserTags:o.allowUserTags,delimiter:o.delimiter,closeAfterSelect:o.closeAfterSelect,createOnBlur:o.createOnBlur,maxItems:o.maxItems>0?o.maxItems:null,plugins:o.maxItems===1?pluginsSingle:pluginsMulti,persist:true,valueField:"value",labelField:"label",searchField:["value","label"],options:tagsList,createFilter:function(input){if(o.allowUserTags)return true;var allow=false;for(var n=0;n"+escape(item.label)+""},option:function(item,escape){if(typeof item.label==="undefined"||!item.label.length)item.label=item.value;return"
"+escape(item.label)+"
"}}});if(o.tagsUrl.length){options.load=function(query,callback){if(!query.length)return callback();var tagsUrl=o.tagsUrl.replace("{q}",encodeURIComponent(query));Inputfields.startSpinner($select);jQuery.ajax({url:tagsUrl,type:"GET",error:function(){Inputfields.stopSpinner($select);callback()},success:function(items){for(var n=0;n"+escape(item.label)+""},option:function(item,escape){if(typeof item.label==="undefined"||!item.label.length)item.label=item.value;return"
"+escape(item.label)+"
"},option_create:function(data,escape){return'
'+addLabel+" "+escape(data.input)+"
"}}}function initInput($input){var o=JSON.parse($input.attr("data-opts"));var options=defaults;options.delimiter=o.delimiter;options.closeAfterSelect=o.closeAfterSelect;options.createOnBlur=o.createOnBlur;options.persist=false;options.maxItems=o.maxItems>0?o.maxItems:null;options.plugins=o.maxItems===1?pluginsSingle:pluginsMulti;options.render=getRenderOptions(o.addLabel);$input.selectize(options)}function initSelect($select){var o=JSON.parse($select.attr("data-opts"));var cfgName=typeof o.cfgName==="undefined"?"":o.cfgName;var tags=cfgName.length?ProcessWire.config[cfgName]:o.tags;var tagsList=[];var n=0;for(var tag in tags){var label=tags[tag];tagsList[n]={value:tag,label:label};n++}var options=jQuery.extend(defaults,{allowUserTags:o.allowUserTags,delimiter:o.delimiter,closeAfterSelect:o.closeAfterSelect,createOnBlur:o.createOnBlur,maxItems:o.maxItems>0?o.maxItems:null,plugins:o.maxItems===1?pluginsSingle:pluginsMulti,persist:true,valueField:"value",labelField:"label",searchField:["value","label"],options:tagsList,createFilter:function(input){if(o.allowUserTags)return true;var allow=false;for(var n=0;n __('Text Tags', __FILE__), // Module Title 'summary' => __('Enables input of user entered tags or selection of predefined tags.', __FILE__), // Module Summary - 'version' => 5, + 'version' => 6, 'icon' => 'tags', ); } @@ -563,6 +563,7 @@ class InputfieldTextTags extends Inputfield implements 'delimiter' => $this->delimiter(), 'maxItems' => $this->maxItems, 'tagsUrl' => $tagsUrl, + 'addLabel' => $this->_('RyAdd'), // Label that appears when adding new tag (the "Add" in "Add [tag] …") ); if($this->hasField) {