From 15fbd6bde89196c7b151e4bd94a0ea0e63e29926 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 30 Jun 2014 19:34:53 +0000 Subject: [PATCH] fixed not working custom fields of type radio --- .../class.etemplate_widget_checkbox.inc.php | 21 +++++++++++++------ ...lass.etemplate_widget_customfields.inc.php | 2 ++ etemplate/js/et2_widget_radiobox.js | 7 +++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_checkbox.inc.php b/etemplate/inc/class.etemplate_widget_checkbox.inc.php index 1f30474d6d..1c65ee0856 100644 --- a/etemplate/inc/class.etemplate_widget_checkbox.inc.php +++ b/etemplate/inc/class.etemplate_widget_checkbox.inc.php @@ -58,7 +58,8 @@ class etemplate_widget_checkbox extends etemplate_widget { self::set_validation_error($form_name,lang('Field must not be empty !!!'),''); } - $value_attr = $this->type == 'radio' ? 'set_value' : 'selected_value'; + $type = $this->type ? $this->type : $this->attrs['type']; + $value_attr = $type == 'radio' ? 'set_value' : 'selected_value'; // defaults for set and unset values if (!$this->attrs[$value_attr] && !$this->attrs['unselected_value']) { @@ -71,7 +72,19 @@ class etemplate_widget_checkbox extends etemplate_widget $selected_value = self::expand_name($this->attrs[$value_attr], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'],$expand['cont']); $unselected_value = self::expand_name($this->attrs['unselected_value'], $expand['c'], $expand['row'], $expand['c_'], $expand['row_'],$expand['cont']); } - if (in_array((string)$selected_value, (array)$value)) + if ($type == 'radio') + { + $options = etemplate_widget_menupopup::selOptions($form_name, true); + if (in_array($value, $options)) + { + $valid = $value; + } + elseif (!isset($valid)) + { + $valid = ''; // do not overwrite value of an other radio-button of the same group (identical name)! + } + } + elseif (in_array((string)$selected_value, (array)$value)) { if ($multiple) { @@ -83,10 +96,6 @@ class etemplate_widget_checkbox extends etemplate_widget $valid = $selected_value; } } - elseif ($this->type == 'radio') - { - if (!isset($valid)) $valid = ''; // do not overwrite value of an other radio-button of the same group (identical name)! - } else // if checkbox is not checked, html returns nothing: eTemplate returns unselected_value (default false) { if ($multiple) diff --git a/etemplate/inc/class.etemplate_widget_customfields.inc.php b/etemplate/inc/class.etemplate_widget_customfields.inc.php index 976ec5c819..46d9104aef 100644 --- a/etemplate/inc/class.etemplate_widget_customfields.inc.php +++ b/etemplate/inc/class.etemplate_widget_customfields.inc.php @@ -306,6 +306,8 @@ class etemplate_widget_customfields extends etemplate_widget_transformer if (!$this->is_readonly($cname, $form_name)) { $value_in = self::get_array($content, $form_name); + // if we have no id / use self::GLOBAL_ID, we have to set $value_in in global namespace for regular widgets validation to find + if (!$this->id) $content = array_merge($content, $value_in); //error_log(__METHOD__."($cname, ...) form_name=$form_name, use-private={$this->attrs['use-private']}, value_in=".array2string($value_in)); $customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields'); if(is_array($value_in)) diff --git a/etemplate/js/et2_widget_radiobox.js b/etemplate/js/et2_widget_radiobox.js index 801aa76b81..83ae20aae1 100644 --- a/etemplate/js/et2_widget_radiobox.js +++ b/etemplate/js/et2_widget_radiobox.js @@ -318,6 +318,13 @@ var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM], * @param {object} _options object with value: label pairs */ set_options: function(_options) { + // Call the destructor of all children + for (var i = this._children.length - 1; i >= 0; i--) + { + this._children[i].free(); + } + this._children = []; + // create radio buttons for each option for(var key in _options) { var attrs = {