diff --git a/administrator/assets/css/bootstrap-tagsinput.css b/administrator/assets/css/bootstrap-tagsinput.css
new file mode 100644
index 00000000..55a8310b
--- /dev/null
+++ b/administrator/assets/css/bootstrap-tagsinput.css
@@ -0,0 +1 @@
+.bootstrap-tagsinput{background-color:#fff;border:1px solid #ccc;box-shadow:inset 0 1px 1px rgba(0,0,0,0.075);display:inline-block;padding:4px 6px;color:#555;vertical-align:middle;border-radius:4px;width:100%;line-height:22px;cursor:text}.bootstrap-tagsinput input{border:none;box-shadow:none;outline:none;background-color:transparent;padding:0 6px;margin:0;width:auto;max-width:inherit}.bootstrap-tagsinput.form-control input::-moz-placeholder{color:#777;opacity:1}.bootstrap-tagsinput.form-control input:-ms-input-placeholder{color:#777}.bootstrap-tagsinput.form-control input::-webkit-input-placeholder{color:#777}.bootstrap-tagsinput input:focus{border:none;box-shadow:none}.bootstrap-tagsinput .tag{margin-right:2px;color:#fff}.bootstrap-tagsinput .tag [data-role="remove"]{margin-left:8px;cursor:pointer}.bootstrap-tagsinput .tag [data-role="remove"]:after{content:"x";padding:0 2px}.bootstrap-tagsinput .tag [data-role="remove"]:hover{box-shadow:inset 0 1px 0 rgba(255,255,255,0.2),0 1px 2px rgba(0,0,0,0.05)}.bootstrap-tagsinput .tag [data-role="remove"]:hover:active{box-shadow:inset 0 3px 5px rgba(0,0,0,0.125)}
diff --git a/administrator/assets/js/bootstrap-tagsinput.min.js b/administrator/assets/js/bootstrap-tagsinput.min.js
new file mode 100644
index 00000000..b878bc10
--- /dev/null
+++ b/administrator/assets/js/bootstrap-tagsinput.min.js
@@ -0,0 +1,7 @@
+/*
+ * bootstrap-tagsinput v0.8.0
+ *
+ */
+
+!function(a){"use strict";function b(b,c){this.isInit=!0,this.itemsArray=[],this.$element=a(b),this.$element.hide(),this.isSelect="SELECT"===b.tagName,this.multiple=this.isSelect&&b.hasAttribute("multiple"),this.objectItems=c&&c.itemValue,this.placeholderText=b.hasAttribute("placeholder")?this.$element.attr("placeholder"):"",this.inputSize=Math.max(1,this.placeholderText.length),this.$container=a('
'),this.$input=a('').appendTo(this.$container),this.$element.before(this.$container),this.build(c),this.isInit=!1}function c(a,b){if("function"!=typeof a[b]){var c=a[b];a[b]=function(a){return a[c]}}}function d(a,b){if("function"!=typeof a[b]){var c=a[b];a[b]=function(){return c}}}function e(a){return a?i.text(a).html():""}function f(a){var b=0;if(document.selection){a.focus();var c=document.selection.createRange();c.moveStart("character",-a.value.length),b=c.text.length}else(a.selectionStart||"0"==a.selectionStart)&&(b=a.selectionStart);return b}function g(b,c){var d=!1;return a.each(c,function(a,c){if("number"==typeof c&&b.which===c)return d=!0,!1;if(b.which===c.which){var e=!c.hasOwnProperty("altKey")||b.altKey===c.altKey,f=!c.hasOwnProperty("shiftKey")||b.shiftKey===c.shiftKey,g=!c.hasOwnProperty("ctrlKey")||b.ctrlKey===c.ctrlKey;if(e&&f&&g)return d=!0,!1}}),d}var h={tagClass:function(a){return"label label-info"},focusClass:"focus",itemValue:function(a){return a?a.toString():a},itemText:function(a){return this.itemValue(a)},itemTitle:function(a){return null},freeInput:!0,addOnBlur:!0,maxTags:void 0,maxChars:void 0,confirmKeys:[13,44],delimiter:",",delimiterRegex:null,cancelConfirmKeysOnEmpty:!1,onTagExists:function(a,b){b.hide().fadeIn()},trimValue:!1,allowDuplicates:!1,triggerChange:!0};b.prototype={constructor:b,add:function(b,c,d){var f=this;if(!(f.options.maxTags&&f.itemsArray.length>=f.options.maxTags)&&(b===!1||b)){if("string"==typeof b&&f.options.trimValue&&(b=a.trim(b)),"object"==typeof b&&!f.objectItems)throw"Can't add objects when itemValue option is not set";if(!b.toString().match(/^\s*$/)){if(f.isSelect&&!f.multiple&&f.itemsArray.length>0&&f.remove(f.itemsArray[0]),"string"==typeof b&&"INPUT"===this.$element[0].tagName){var g=f.options.delimiterRegex?f.options.delimiterRegex:f.options.delimiter,h=b.split(g);if(h.length>1){for(var i=0;if.options.maxInputLength)){var o=a.Event("beforeItemAdd",{item:b,cancel:!1,options:d});if(f.$element.trigger(o),!o.cancel){f.itemsArray.push(b);var p=a(''+e(k)+'');p.data("item",b),f.findInputWrapper().before(p),p.after(" ");var q=a('option[value="'+encodeURIComponent(j)+'"]',f.$element).length||a('option[value="'+e(j)+'"]',f.$element).length;if(f.isSelect&&!q){var r=a("");r.data("item",b),r.attr("value",j),f.$element.append(r)}c||f.pushVal(f.options.triggerChange),(f.options.maxTags===f.itemsArray.length||f.items().toString().length===f.options.maxInputLength)&&f.$container.addClass("bootstrap-tagsinput-max"),a(".typeahead, .twitter-typeahead",f.$container).length&&f.$input.typeahead("val",""),this.isInit?f.$element.trigger(a.Event("itemAddedOnInit",{item:b,options:d})):f.$element.trigger(a.Event("itemAdded",{item:b,options:d}))}}}else if(f.options.onTagExists){var s=a(".tag",f.$container).filter(function(){return a(this).data("item")===n});f.options.onTagExists(b,s)}}}},remove:function(b,c,d){var e=this;if(e.objectItems&&(b="object"==typeof b?a.grep(e.itemsArray,function(a){return e.options.itemValue(a)==e.options.itemValue(b)}):a.grep(e.itemsArray,function(a){return e.options.itemValue(a)==b}),b=b[b.length-1]),b){var f=a.Event("beforeItemRemove",{item:b,cancel:!1,options:d});if(e.$element.trigger(f),f.cancel)return;a(".tag",e.$container).filter(function(){return a(this).data("item")===b}).remove(),a("option",e.$element).filter(function(){return a(this).data("item")===b}).remove(),-1!==a.inArray(b,e.itemsArray)&&e.itemsArray.splice(a.inArray(b,e.itemsArray),1)}c||e.pushVal(e.options.triggerChange),e.options.maxTags>e.itemsArray.length&&e.$container.removeClass("bootstrap-tagsinput-max"),e.$element.trigger(a.Event("itemRemoved",{item:b,options:d}))},removeAll:function(){var b=this;for(a(".tag",b.$container).remove(),a("option",b.$element).remove();b.itemsArray.length>0;)b.itemsArray.pop();b.pushVal(b.options.triggerChange)},refresh:function(){var b=this;a(".tag",b.$container).each(function(){var c=a(this),d=c.data("item"),f=b.options.itemValue(d),g=b.options.itemText(d),h=b.options.tagClass(d);if(c.attr("class",null),c.addClass("tag "+e(h)),c.contents().filter(function(){return 3==this.nodeType})[0].nodeValue=e(g),b.isSelect){var i=a("option",b.$element).filter(function(){return a(this).data("item")===d});i.attr("value",f)}})},items:function(){return this.itemsArray},pushVal:function(){var b=this,c=a.map(b.items(),function(a){return b.options.itemValue(a).toString()});b.$element.val(c,!0),b.options.triggerChange&&b.$element.trigger("change")},build:function(b){var e=this;if(e.options=a.extend({},h,b),e.objectItems&&(e.options.freeInput=!1),c(e.options,"itemValue"),c(e.options,"itemText"),d(e.options,"tagClass"),e.options.typeahead){var i=e.options.typeahead||{};d(i,"source"),e.$input.typeahead(a.extend({},i,{source:function(b,c){function d(a){for(var b=[],d=0;d$1")}}))}if(e.options.typeaheadjs){var j=null,k={},l=e.options.typeaheadjs;a.isArray(l)?(j=l[0],k=l[1]):k=l,e.$input.typeahead(j,k).on("typeahead:selected",a.proxy(function(a,b){k.valueKey?e.add(b[k.valueKey]):e.add(b),e.$input.typeahead("val","")},e))}e.$container.on("click",a.proxy(function(a){e.$element.attr("disabled")||e.$input.removeAttr("disabled"),e.$input.focus()},e)),e.options.addOnBlur&&e.options.freeInput&&e.$input.on("focusout",a.proxy(function(b){0===a(".typeahead, .twitter-typeahead",e.$container).length&&(e.add(e.$input.val()),e.$input.val(""))},e)),e.$container.on({focusin:function(){e.$container.addClass(e.options.focusClass)},focusout:function(){e.$container.removeClass(e.options.focusClass)}}),e.$container.on("keydown","input",a.proxy(function(b){var c=a(b.target),d=e.findInputWrapper();if(e.$element.attr("disabled"))return void e.$input.attr("disabled","disabled");switch(b.which){case 8:if(0===f(c[0])){var g=d.prev();g.length&&e.remove(g.data("item"))}break;case 46:if(0===f(c[0])){var h=d.next();h.length&&e.remove(h.data("item"))}break;case 37:var i=d.prev();0===c.val().length&&i[0]&&(i.before(d),c.focus());break;case 39:var j=d.next();0===c.val().length&&j[0]&&(j.after(d),c.focus())}var k=c.val().length;Math.ceil(k/5);c.attr("size",Math.max(this.inputSize,c.val().length))},e)),e.$container.on("keypress","input",a.proxy(function(b){var c=a(b.target);if(e.$element.attr("disabled"))return void e.$input.attr("disabled","disabled");var d=c.val(),f=e.options.maxChars&&d.length>=e.options.maxChars;e.options.freeInput&&(g(b,e.options.confirmKeys)||f)&&(0!==d.length&&(e.add(f?d.substr(0,e.options.maxChars):d),c.val("")),e.options.cancelConfirmKeysOnEmpty===!1&&b.preventDefault());var h=c.val().length;Math.ceil(h/5);c.attr("size",Math.max(this.inputSize,c.val().length))},e)),e.$container.on("click","[data-role=remove]",a.proxy(function(b){e.$element.attr("disabled")||e.remove(a(b.target).closest(".tag").data("item"))},e)),e.options.itemValue===h.itemValue&&("INPUT"===e.$element[0].tagName?e.add(e.$element.val()):a("option",e.$element).each(function(){e.add(a(this).attr("value"),!0)}))},destroy:function(){var a=this;a.$container.off("keypress","input"),a.$container.off("click","[role=remove]"),a.$container.remove(),a.$element.removeData("tagsinput"),a.$element.show()},focus:function(){this.$input.focus()},input:function(){return this.$input},findInputWrapper:function(){for(var b=this.$input[0],c=this.$container[0];b&&b.parentNode!==c;)b=b.parentNode;return a(b)}},a.fn.tagsinput=function(c,d,e){var f=[];return this.each(function(){var g=a(this).data("tagsinput");if(g)if(c||d){if(void 0!==g[c]){if(3===g[c].length&&void 0!==e)var h=g[c](d,null,e);else var h=g[c](d);void 0!==h&&f.push(h)}}else f.push(g);else g=new b(this,c),a(this).data("tagsinput",g),f.push(g),"SELECT"===this.tagName&&a("option",a(this)).attr("selected","selected"),a(this).val(a(this).val())}),"string"==typeof c?f.length>1?f:f[0]:f},a.fn.tagsinput.Constructor=b;var i=a("");a(function(){a("input[data-role=tagsinput], select[multiple][data-role=tagsinput]").tagsinput()})}(window.jQuery);
+//# sourceMappingURL=bootstrap-tagsinput.min.js.map
diff --git a/administrator/assets/js/tjlist.js b/administrator/assets/js/tjlist.js
index 96523011..477805f4 100644
--- a/administrator/assets/js/tjlist.js
+++ b/administrator/assets/js/tjlist.js
@@ -6,10 +6,19 @@
* @license GNU General Public License version 2, or later
*/
var tjlist = {
-
addOtherOption: function (element) {
jQuery(tjlist.getTextBox(element)).insertAfter(element.next(".chzn-container"));
+
+ setTimeout(function() {
+ element.siblings('div.tjfieldTjListOtherText').children('.bootstrap-tagsinput').children().focus();
+
+ if (element.attr('multiple') == undefined)
+ {
+ element.siblings('div.tjfieldTjListOtherText').children().focus();
+ }
+
+ }, 100);
},
removeOtherOption: function (element) {
@@ -21,7 +30,22 @@ var tjlist = {
isRequired = (element.attr('required') != undefined) ? 'required="required"' : '',
requiredClass = (isRequired != '') ? 'required' : '';
- return '
';
+ if (element.attr('multiple') != undefined)
+ {
+ this.loadTagsinputjs();
+ var tagInput = (element.attr('multiple') != undefined) ? 'data-role="tagsinput"' : '';
+ }
+
+ return '
';
+ },
+ loadTagsinputjs: function()
+ {
+ var head= document.getElementsByTagName('head')[0];
+ var script= document.createElement('script');
+
+ // @Todo - Decide right place to store below JS
+ script.src= Joomla.getOptions('system.paths').base +'/administrator/components/com_tjfields/assets/js/bootstrap-tagsinput.min.js';
+ head.appendChild(script);
}
}
diff --git a/administrator/assets/js/tjlist.min.js b/administrator/assets/js/tjlist.min.js
index d3fc345a..8bb4a17d 100644
--- a/administrator/assets/js/tjlist.min.js
+++ b/administrator/assets/js/tjlist.min.js
@@ -1 +1 @@
-var tjlist={addOtherOption:function(t){jQuery(tjlist.getTextBox(t)).insertAfter(t.next(".chzn-container"))},removeOtherOption:function(t){t.siblings("div.tjfieldTjListOtherText").remove()},getTextBox:function(t){var e=t.attr("name"),r=t.attr("id"),i=null!=t.attr("required")?'required="required"':"";return'
'}};jQuery(document).ready(function(){jQuery(document).on("change",".tjfieldTjList",function(){var t=jQuery(this).val();-1!==jQuery.inArray(Joomla.JText._("COM_TJFIELDS_TJLIST_OTHER_OPTION_VALUE"),t)||t==Joomla.JText._("COM_TJFIELDS_TJLIST_OTHER_OPTION_VALUE")?0==jQuery('input[name="'+jQuery(this).attr("name")+'"]').length&&tjlist.addOtherOption(jQuery(this)):tjlist.removeOtherOption(jQuery(this))})});
+var tjlist={addOtherOption:function(element){jQuery(tjlist.getTextBox(element)).insertAfter(element.next(".chzn-container"));setTimeout(function(){element.siblings("div.tjfieldTjListOtherText").children(".bootstrap-tagsinput").children().focus();if(element.attr("multiple")==undefined){element.siblings("div.tjfieldTjListOtherText").children().focus()}},100)},removeOtherOption:function(element){element.siblings("div.tjfieldTjListOtherText").remove()},getTextBox:function(element){var inputName=element.attr("name"),inputId=element.attr("id"),isRequired=element.attr("required")!=undefined?'required="required"':"",requiredClass=isRequired!=""?"required":"";if(element.attr("multiple")!=undefined){this.loadTagsinputjs();var tagInput=element.attr("multiple")!=undefined?'data-role="tagsinput"':""}return'
'},loadTagsinputjs:function(){var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");script.src=Joomla.getOptions("system.paths").base+"/administrator/components/com_tjfields/assets/js/bootstrap-tagsinput.min.js";head.appendChild(script)}};jQuery(document).ready(function(){jQuery(document).on("change",".tjfieldTjList",function(){var selectedVal=jQuery(this).val();if(jQuery.inArray(Joomla.JText._("COM_TJFIELDS_TJLIST_OTHER_OPTION_VALUE"),selectedVal)!==-1||selectedVal==Joomla.JText._("COM_TJFIELDS_TJLIST_OTHER_OPTION_VALUE")){if(jQuery('input[name="'+jQuery(this).attr("name")+'"]').length==0){tjlist.addOtherOption(jQuery(this))}}else{tjlist.removeOtherOption(jQuery(this))}})});
diff --git a/administrator/models/fields/tjlist.php b/administrator/models/fields/tjlist.php
index b6b576ef..00cff908 100644
--- a/administrator/models/fields/tjlist.php
+++ b/administrator/models/fields/tjlist.php
@@ -14,6 +14,7 @@
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
+use Joomla\CMS\Factory;
/**
* Form Field class for the Joomla Platform.
@@ -105,9 +106,15 @@ protected function getInput()
$html = parent::getInput();
- $doc = JFactory::getDocument();
+ $doc = Factory::getDocument();
$doc->addScript(JUri::root() . 'administrator/components/com_tjfields/assets/js/tjlist.min.js');
+ if ($this->multiple)
+ {
+ $doc->addStyleSheet(JUri::root() . 'administrator/components/com_tjfields/assets/css/bootstrap-tagsinput.css');
+ $doc->addScript(JUri::root() . 'administrator/components/com_tjfields/assets/js/bootstrap-tagsinput.min.js');
+ }
+
$options = $this->getOptions();
if ($this->element['other'])
@@ -131,7 +138,8 @@ function ($e) {
if (empty($valueFromSelectList))
{
- $this->otherSelectedValue = $this->value[0];
+ // Remove prefix values from other text values
+ $this->otherSelectedValue = str_replace($this->type . ':-', '', $this->value[0]);
}
}
elseif ($this->multiple)
@@ -150,7 +158,10 @@ function ($e) {
if (!empty($otherValues))
{
- $this->otherSelectedValue = $otherValues[0];
+ $this->otherSelectedValue = implode(',', $otherValues);
+
+ // Remove prefix values from other text values
+ $this->otherSelectedValue = str_replace($this->type . ':-', '', $this->otherSelectedValue);
}
}
}
@@ -202,8 +213,21 @@ public function getOptions()
private function getInputBox()
{
$text = '
';
- $text .= 'otherInputRequired . '
- name="' . $this->name . '" id="' . $this->id . '" value="' . $this->otherSelectedValue . '" aria-invalid="false">
';
+
+ // Check multiple select option true or not
+ if ($this->multiple)
+ {
+ // Enable the bootstrap taging input
+ $text .= 'otherInputRequired . ' name="' . $this->name . '" id="' . $this->id . '" value="' . $this->otherSelectedValue . '" aria-invalid="false">';
+ }
+ else
+ {
+ $text .= 'otherInputRequired . '
+ name="' . $this->name . '" id="' . $this->id . '" value="' . $this->otherSelectedValue . '" aria-invalid="false">';
+ }
+
+ $text .= '';
return $text;
}
diff --git a/site/helpers/tjfields.php b/site/helpers/tjfields.php
index 1cdddcab..12c1d8e9 100644
--- a/site/helpers/tjfields.php
+++ b/site/helpers/tjfields.php
@@ -307,6 +307,68 @@ public function saveFieldsValue($data)
}
}
}
+ elseif ($field->type == 'tjlist')
+ {
+ // Check for Tjlist - start
+ $tjListParams = json_decode($field->params);
+
+ if ($tjListParams->other)
+ {
+ // Get all the fields of the specified client
+ JLoader::import('components.com_tjfields.models.options', JPATH_ADMINISTRATOR);
+ $tjFieldOptionsModel = JModelLegacy::getInstance('Options', 'TjfieldsModel', array('ignore_request' => true));
+ $tjFieldOptionsModel->setState('filter.field_id', $field->id);
+ $optionsValue = $tjFieldOptionsModel->getItems();
+
+ // Get array of dropdown values
+ $otherValues = array_column($optionsValue, 'value');
+ }
+
+ if (is_array($fieldValue))
+ {
+ $fieldVal = array();
+
+ if ($tjListParams->other)
+ {
+ $otherValues[] = $field->type . 'othervalue';
+
+ foreach ($fieldValue as $key => $listfieldVale)
+ {
+ if (strpos($listfieldVale, ','))
+ {
+ $fieldVal = explode(',', $listfieldVale);
+
+ // Add prefix for other values for tjlist field
+ $fieldVal = preg_filter('/^/', $field->type . ':-', $fieldVal);
+ unset($fieldValue[$key]);
+ }
+ elseif (!in_array($listfieldVale, $otherValues))
+ {
+ $fieldValue[$key] = $field->type . ':-' . $listfieldVale;
+ }
+ }
+
+ if (!empty($fieldVal))
+ {
+ $fieldValue = array_merge($fieldValue, $fieldVal);
+ }
+ }
+
+ $this->saveMultiValuedFieldData($fieldValue, $field->client, $data['content_id'], $field->id, $fieldStoredValues);
+ }
+ else
+ {
+ // Check other option enable for tjlist field
+
+ if ($tjListParams->other && !in_array($fieldValue, $otherValues))
+ {
+ // Add prefix for other values for tjlist field
+ $fieldValue = $field->type . ':-' . $fieldValue;
+ }
+
+ $this->saveSingleValuedFieldData($fieldValue, $field->client, $data['content_id'], $field->id, $fieldStoredValues);
+ }
+ }
elseif (is_array($fieldValue))
{
if (strpos($fieldValue[0], ','))
@@ -1485,15 +1547,17 @@ public function getOptions($field_id, $option_value = '')
if (!empty($otherValues))
{
- $tjListOtherObj = new stdClass;
-
- $tjListOtherObj->options = $otherValues[0];
- $tjListOtherObj->default_option = '';
- $tjListOtherObj->value = $otherValues[0];
-
- $extra_options[] = $tjListOtherObj;
+ foreach ($otherValues as $othervalue)
+ {
+ $tjListOtherObj = new stdClass;
+ $tjListOtherObj->default_option = '';
+ $tjListOtherObj->options = $othervalue;
+ $tjListOtherObj->value = $othervalue;
+ $extra_options[] = $tjListOtherObj;
+ }
}
}
+
// Check for Tjlist - end
}
}