mirror of
https://github.com/processwire/processwire.git
synced 2025-08-13 02:04:35 +02:00
Fix issue processwire/processwire-issues#1817 by adding support for translatable 'Add' label in InputfieldTextTags module
This commit is contained in:
@@ -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 '<div>' + escape(item.label) + '</div>';
|
||||
},
|
||||
option: function(item, escape) {
|
||||
if(typeof item.label === "undefined" || !item.label.length) item.label = item.value;
|
||||
return '<div>' + escape(item.label) + '</div>';
|
||||
},
|
||||
option_create: function(data, escape) {
|
||||
return '<div class="create">' + addLabel + ' <strong>' + escape(data.input) + '</strong>…</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 '<div>' + escape(item.label) + '</div>';
|
||||
},
|
||||
option: function(item, escape) {
|
||||
if(typeof item.label === "undefined" || !item.label.length) item.label = item.value;
|
||||
return '<div>' + escape(item.label) + '</div>';
|
||||
}
|
||||
}
|
||||
render: getRenderOptions(o.addLabel)
|
||||
/*
|
||||
onDropdownOpen: function($dropdown) {
|
||||
$dropdown.closest('li, .InputfieldImageEdit').css('z-index', 100);
|
||||
|
@@ -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<tags.length;n++){if(typeof tags[input]!=="undefined"){allow=true;break}}return allow},render:{item:function(item,escape){if(typeof item.label==="undefined"||!item.label.length)item.label=item.value;return"<div>"+escape(item.label)+"</div>"},option:function(item,escape){if(typeof item.label==="undefined"||!item.label.length)item.label=item.value;return"<div>"+escape(item.label)+"</div>"}}});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<items.length;n++){var item=items[n];if(typeof item==="object"){if(typeof item.label==="undefined"){item.label=item.value;items[n]=item}}else{items[n]={value:item,label:item}}}Inputfields.stopSpinner($select);callback(items)}})}}$select.selectize(options)}var $inputs=jQuery(".InputfieldTextTagsInput:not(.selectized)",$parent);var $selects=jQuery(".InputfieldTextTagsSelect:not(.selectized)",$parent);if($inputs.length){$inputs.each(function(){$input=jQuery(this);initInput($input)})}if($selects.length){$selects.each(function(){var $select=jQuery(this);initSelect($select)})}}jQuery(document).ready(function($){InputfieldTextTags();$(document).on("reloaded",".InputfieldTextTags, .InputfieldPage",function(){InputfieldTextTags($(this))})});
|
||||
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 getRenderOptions(addLabel){return{item:function(item,escape){if(typeof item.label==="undefined"||!item.label.length)item.label=item.value;return"<div>"+escape(item.label)+"</div>"},option:function(item,escape){if(typeof item.label==="undefined"||!item.label.length)item.label=item.value;return"<div>"+escape(item.label)+"</div>"},option_create:function(data,escape){return'<div class="create">'+addLabel+" <strong>"+escape(data.input)+"</strong>…</div>"}}}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<tags.length;n++){if(typeof tags[input]!=="undefined"){allow=true;break}}return allow},render:getRenderOptions(o.addLabel)});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<items.length;n++){var item=items[n];if(typeof item==="object"){if(typeof item.label==="undefined"){item.label=item.value;items[n]=item}}else{items[n]={value:item,label:item}}}Inputfields.stopSpinner($select);callback(items)}})}}$select.selectize(options)}var $inputs=jQuery(".InputfieldTextTagsInput:not(.selectized)",$parent);var $selects=jQuery(".InputfieldTextTagsSelect:not(.selectized)",$parent);if($inputs.length){$inputs.each(function(){$input=jQuery(this);initInput($input)})}if($selects.length){$selects.each(function(){var $select=jQuery(this);initSelect($select)})}}jQuery(document).ready(function($){InputfieldTextTags();$(document).on("reloaded",".InputfieldTextTags, .InputfieldPage",function(){InputfieldTextTags($(this))})});
|
@@ -33,7 +33,7 @@
|
||||
* @property-read array $arrayValue
|
||||
* @property string|null $pageSelector
|
||||
*
|
||||
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
|
||||
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
|
||||
* https://processwire.com
|
||||
*
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ class InputfieldTextTags extends Inputfield implements
|
||||
return array(
|
||||
'title' => __('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) {
|
||||
|
Reference in New Issue
Block a user