diff --git a/etemplate/inc/class.etemplate_widget_tree.inc.php b/etemplate/inc/class.etemplate_widget_tree.inc.php index ccb892e868..e65e3bcdbc 100644 --- a/etemplate/inc/class.etemplate_widget_tree.inc.php +++ b/etemplate/inc/class.etemplate_widget_tree.inc.php @@ -125,6 +125,20 @@ class etemplate_widget_tree extends etemplate_widget return false; } + /** + * Check if given $id is cat_id attribute of one of given array members + * + * @param int $id + * @param array $cats + * @return boolean + */ + public static function in_cats($id, array $cats) + { + return (boolean)array_filter($cats, function($cat) use($id){ + return $cat['id'] == $id; + }); + } + /** * Validate input * @@ -149,7 +163,7 @@ class etemplate_widget_tree extends etemplate_widget $allowed += self::selOptions($form_name); foreach((array) $value as $val) { - if ($this->type == 'tree-cat' && !($this->attrs['multiple'] && !$val) && !isset($allowed[$val]) || + if ($this->type == 'tree-cat' && !($this->attrs['multiple'] && !$val) && !self::in_cats($val, $allowed) || $this->type == 'tree' && !self::in_tree($val, $allowed)) { self::set_validation_error($form_name,lang("'%1' is NOT allowed%2)!", $val, @@ -169,7 +183,7 @@ class etemplate_widget_tree extends etemplate_widget self::set_validation_error($form_name,lang('Field must not be empty !!!',$value),''); } $valid =& self::get_array($validated, $form_name, true); - $valid = $value; + if (true) $valid = $value; //error_log(__METHOD__."() $form_name: ".array2string($value_in).' --> '.array2string($value).', allowed='.array2string($allowed)); } } diff --git a/etemplate/js/et2_widget_tree.js b/etemplate/js/et2_widget_tree.js index 4a253ddf40..f48cea78d0 100644 --- a/etemplate/js/et2_widget_tree.js +++ b/etemplate/js/et2_widget_tree.js @@ -151,7 +151,7 @@ var et2_tree = et2_inputWidget.extend( // Try again according to ID if(!content_options) content_options = this.getArrayMgr("sel_options").getEntry(this.id); - if(_attrs["select_options"] && content_options) + if(_attrs["select_options"] && !jQuery.isEmptyObject(_attrs["select_options"]) && content_options) { _attrs["select_options"] = jQuery.extend({},_attrs["select_options"],content_options); } else if (content_options) { @@ -250,10 +250,11 @@ var et2_tree = et2_inputWidget.extend( } // Structure data for category tree - if(this._type == 'tree-cat' && !jQuery.isArray(options)) { + if(this._type == 'tree-cat') + { var data = {id:0,item:[]}; - var stack = []; - for(var key in options) + var stack = {}; + for(var key=0; key < options.length; key++) { // See if item has an icon if(options[key].data && typeof options[key].data.icon !== 'undefined' && options[key].data.icon)