fixed not working custom fields of type radio

This commit is contained in:
Ralf Becker 2014-06-30 19:34:53 +00:00
parent e63984884f
commit 15fbd6bde8
3 changed files with 24 additions and 6 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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 = {