- Add required attribute to radiobox so it can pass it on to radio buttons

- Add detached DOM support to play nice in datagrid rows
This commit is contained in:
Nathan Gray 2013-06-25 20:53:39 +00:00
parent ac45bd0625
commit 442c9e6356

View File

@ -143,7 +143,7 @@ var et2_radiobox_ro = et2_valueWidget.extend([et2_IDetachedDOM],
"label": {
"name": "Label",
"default": "",
"type": "string",
"type": "string"
}
},
@ -202,7 +202,7 @@ et2_register_widget(et2_radiobox_ro, ["radio_ro"]);
*
* @augments et2_valueWidget
*/
var et2_radioGroup = et2_valueWidget.extend(
var et2_radioGroup = et2_valueWidget.extend([et2_IDetachedDOM],
{
attributes: {
"label": {
@ -235,6 +235,12 @@ var et2_radioGroup = et2_valueWidget.extend(
"type": "any",
"default": {},
"description": "Options for radio buttons. Should be {value: label, ...}"
},
"required": {
"name": "Required",
"default": false,
"type": "boolean",
"description": "If required, the user must select one of the options before the form can be submitted"
}
},
@ -252,11 +258,16 @@ var et2_radioGroup = et2_valueWidget.extend(
this.node = $j(document.createElement("div"))
.addClass("et2_vbox")
.addClass("et2_box_widget");
if(this.options.required)
{
// This isn't strictly allowed, but it works
this.node.attr("required","required");
}
this.setDOMNode(this.node[0]);
// The supported widget classes array defines a whitelist for all widget
// classes or interfaces child widgets have to support.
this.supportedWidgetClasses = [et2_radiobox];
this.supportedWidgetClasses = [et2_radiobox,et2_radiobox_ro];
},
set_value: function(_value) {
@ -286,7 +297,8 @@ var et2_radioGroup = et2_valueWidget.extend(
label: _options[key],
ro_true: this.options.ro_true,
ro_false: this.options.ro_false,
readonly: this.options.readonly
readonly: this.options.readonly,
required: this.options.required
};
var radio = et2_createWidget("radio", attrs, this);
}
@ -332,6 +344,24 @@ var et2_radioGroup = et2_valueWidget.extend(
}
this._labelContainer = null;
}
},
/**
* Code for implementing et2_IDetachedDOM
* 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
*/
getDetachedAttributes: function(_attrs)
{
},
getDetachedNodes: function()
{
return [this.getDOMNode()];
},
setDetachedAttributes: function(_nodes, _values)
{
}
});