fixed radiobutton not (always) returning correct value plus fixing ide warnings

This commit is contained in:
Ralf Becker 2014-02-13 09:50:49 +00:00
parent e84d243b5d
commit 8d86f8496b

View File

@ -19,13 +19,13 @@
/** /**
* Class which implements the "radiobox" XET-Tag * Class which implements the "radiobox" XET-Tag
* *
* A radio button belongs to same group by giving all buttons of a group same id! * A radio button belongs to same group by giving all buttons of a group same id!
* *
* set_value iterates over all of them and (un)checks them depending on given value. * set_value iterates over all of them and (un)checks them depending on given value.
* *
* @augments et2_inputWidget * @augments et2_inputWidget
*/ */
var et2_radiobox = et2_inputWidget.extend( var et2_radiobox = et2_inputWidget.extend(
{ {
attributes: { attributes: {
@ -48,12 +48,12 @@ var et2_radiobox = et2_inputWidget.extend(
"description": "What should be displayed when readonly and not selected" "description": "What should be displayed when readonly and not selected"
} }
}, },
legacyOptions: ["set_value", "ro_true", "ro_false"], legacyOptions: ["set_value", "ro_true", "ro_false"],
/** /**
* Constructor * Constructor
* *
* @memberOf et2_radiobox * @memberOf et2_radiobox
*/ */
init: function() { init: function() {
@ -74,10 +74,10 @@ var et2_radiobox = et2_inputWidget.extend(
this.setDOMNode(this.input[0]); this.setDOMNode(this.input[0]);
}, },
/** /**
* Overwritten to set different DOM level ids by appending set_value * Overwritten to set different DOM level ids by appending set_value
* *
* @param _id * @param _id
*/ */
set_id: function(_id) set_id: function(_id)
@ -103,8 +103,10 @@ var et2_radiobox = et2_inputWidget.extend(
/** /**
* Override default to match against set/unset value AND iterate over all siblings with same id * Override default to match against set/unset value AND iterate over all siblings with same id
*
* @param {string} _value
*/ */
set_value: function(_value) set_value: function(_value)
{ {
this.getRoot().iterateOver(function(radio) this.getRoot().iterateOver(function(radio)
{ {
@ -116,13 +118,22 @@ var et2_radiobox = et2_inputWidget.extend(
}, },
/** /**
* Override default to return unchecked value * Override default to iterate over all siblings with same id
*
* @return {string}
*/ */
getValue: function() { getValue: function()
if(jQuery("input:checked", this._parent.getDOMNode()).val() == this.options.set_value) { {
return this.options.set_value; var val = this.options.value; // initial value, when form is loaded
} this.getRoot().iterateOver(function(radio)
return null; {
if (radio.id == this.id && radio.input && radio.input.prop('checked'))
{
val = radio.options.set_value;
}
}, this, et2_radiobox);
return val;
} }
}); });
et2_register_widget(et2_radiobox, ["radio"]); et2_register_widget(et2_radiobox, ["radio"]);
@ -130,7 +141,7 @@ et2_register_widget(et2_radiobox, ["radio"]);
/** /**
* @augments et2_valueWidget * @augments et2_valueWidget
*/ */
var et2_radiobox_ro = et2_valueWidget.extend([et2_IDetachedDOM], var et2_radiobox_ro = et2_valueWidget.extend([et2_IDetachedDOM],
{ {
attributes: { attributes: {
"set_value": { "set_value": {
@ -160,7 +171,7 @@ var et2_radiobox_ro = et2_valueWidget.extend([et2_IDetachedDOM],
/** /**
* Constructor * Constructor
* *
* @memberOf et2_radiobox_ro * @memberOf et2_radiobox_ro
*/ */
init: function() { init: function() {
@ -175,6 +186,8 @@ var et2_radiobox_ro = et2_valueWidget.extend([et2_IDetachedDOM],
/** /**
* Override default to match against set/unset value * Override default to match against set/unset value
*
* @param {string} _value
*/ */
set_value: function(_value) { set_value: function(_value) {
if(_value == this.options.set_value) { if(_value == this.options.set_value) {
@ -186,6 +199,8 @@ var et2_radiobox_ro = et2_valueWidget.extend([et2_IDetachedDOM],
/** /**
* Code for implementing et2_IDetachedDOM * Code for implementing et2_IDetachedDOM
*
* @param {array} _attrs
*/ */
getDetachedAttributes: function(_attrs) getDetachedAttributes: function(_attrs)
{ {
@ -210,10 +225,10 @@ et2_register_widget(et2_radiobox_ro, ["radio_ro"]);
/** /**
* A group of radio buttons * A group of radio buttons
* *
* @augments et2_valueWidget * @augments et2_valueWidget
*/ */
var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM], var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM],
{ {
attributes: { attributes: {
"label": { "label": {
@ -259,7 +274,7 @@ var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM],
/** /**
* Constructor * Constructor
* *
* @param parent * @param parent
* @param attrs * @param attrs
* @memberOf et2_radioGroup * @memberOf et2_radioGroup
@ -296,7 +311,8 @@ var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM],
/** /**
* Set a bunch of radio buttons * Set a bunch of radio buttons
* Options should be {value: label, ...} *
* @param {object} _options object with value: label pairs
*/ */
set_options: function(_options) { set_options: function(_options) {
for(var key in _options) for(var key in _options)
@ -322,6 +338,8 @@ var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM],
/** /**
* Set a label on the group of radio buttons * Set a label on the group of radio buttons
*
* @param {string} _value
*/ */
set_label: function(_value) { set_label: function(_value) {
// Abort if ther was no change in the label // Abort if ther was no change in the label
@ -335,7 +353,7 @@ var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM],
// Create the label container if it didn't exist yet // Create the label container if it didn't exist yet
if (this._labelContainer == null) if (this._labelContainer == null)
{ {
this._labelContainer = $j(document.createElement("label")) this._labelContainer = $j(document.createElement("label"));
this.getSurroundings().insertDOMNode(this._labelContainer[0]); this.getSurroundings().insertDOMNode(this._labelContainer[0]);
} }
@ -360,11 +378,13 @@ var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM],
this._labelContainer = null; this._labelContainer = null;
} }
}, },
/** /**
* Code for implementing et2_IDetachedDOM * Code for implementing et2_IDetachedDOM
* This doesn't need to be implemented. * This doesn't need to be implemented.
* Individual widgets are detected and handled by the grid, but the interface is needed for this to happen * Individual widgets are detected and handled by the grid, but the interface is needed for this to happen
*
* @param {object} _attrs
*/ */
getDetachedAttributes: function(_attrs) getDetachedAttributes: function(_attrs)
{ {