baseradio.lzx
<library>
<include href="base/baseformitem.lzx"/>
<node id="_lzrbcontroller">
<attribute name="groups" value="$once{{}}"/>
<attribute name="defaultGroupName" value="lzdefaultgroup
" type="string"/>
<method name="createGroup" args="groupname,rb">
if(rb['findForm']){
var groupPlacement = rb.findForm();
} else {
var groupPlacement = null;
}
if (groupPlacement == null) groupPlacement = this;
var group = new lz.baseradiogroup(groupPlacement,
{ name: groupname,
submitname: rb.submitname,
submit: rb.submit,
datapath: rb.groupdatapath } );
return (this.groups[groupname] = group);
</method>
<method name="findRadioGroupAncestor" args="rb">
var p = rb.parent;
while (p != canvas && ! (p instanceof lz.baseradiogroup)) {
p = p.parent;
}
return (p != canvas ? p : null);
</method>
<method name="addRadioButton" args="rb">
var group = null;
var groupname = rb['groupname'];
if (groupname != null) {
group = this.groups[groupname];
if (!group) group = this.createGroup(groupname, rb);
} else if (rb.group != null) {
group = rb.group;
groupname = group.name;
} else {
group = this.findRadioGroupAncestor(rb);
}
// if we still haven't found a group, use default.
if (! group) {
Debug.write('WARNING: group and groupname not defined. ' +
'Using default baseradiogroup for', rb);
group = this.groups[this.defaultGroupName];
if (!group) {
group = this.createGroup(this.defaultGroupName, rb);
}
}
rb.group = group;
rb.groupname = group.name;
group.addRadioButton(rb);
</method>
</node>
<class name="baseradiobutton" extends="basecomponent">
<attribute name="groupname" value="$once{null}" type="string"/>
<attribute name="group" value="null
"/>
<attribute name="value" value="null
"/>
<attribute name="submit" value="true
"/>
<attribute name="submitname" value="
" type="string"/>
<attribute name="groupdatapath" value="$once{null}" type="string"/>
<attribute name="selected" value="false
" setter="this._select(selected)"/>
<event name="onselected"/>
<attribute name="_sendonselected" value="false
"/>
<method name="init">
super.init();
_lzrbcontroller.addRadioButton(this);
// Call onselected if we selected this radiobutton very early and
// didn't send one before.
if (this._sendonselected) {
this.onselected.sendEvent(this.selected);
}
</method>
<handler name="onclick">
this._select(true);
</handler>
<method name="_select" args="s">
if (this['selected'] == s) return;
this.selected = s;
// This ensures we send onselected event even if we select
// radiobutton early, i.e., before it's fully inited.
if (! this.isinited) {
this._sendonselected = true;
return;
}
// If we send event before init, make sure we don't send it during
// init.
this._sendonselected = false;
if (s) this.group.setValue( this.value );
if (this.onselected) this.onselected.sendEvent(s);
</method>
<method name="_showEnabled">
if (this['_applystyle']) {
this._applystyle(this.style);
}
</method>
</class>
<class name="baseradiogroup" extends="baseformitem">
<attribute name="value" value="null
" setter="this.setValue(value, false)"/>
<attribute name="_rbuttons" value="null
"/>
<method name="addRadioButton" args="rb">
// If a parent form isn't found enclosed in radiogroup, look for it
// in the first of the radiobuttons.
if (this._rbuttons == null && this._parentform == null) {
var p = rb.immediateparent;
while (p != canvas) {
if (p[ 'formdata' ]) {
// found a form parent
p.addFormItem(this);
this._parentform = p;
break;
}
p = p.immediateparent;
}
}
if (this._rbuttons == null) this._rbuttons = [];
if (rb.selected) {
this.setValue(rb.value, false);
} else {
if (rb.value == this.value) {
if (!rb.selected) rb.setAttribute('selected', true);
} else {
if ( rb.selected) rb.setAttribute('selected', false);
}
}
this._rbuttons.push(rb);
</method>
<method name="setValue" args="value,isinitvalue=null">
if (this['value'] == value) return;
if (this._rbuttons != null) {
for (var i=0; i < this._rbuttons.length; i++) {
var rb = this._rbuttons[i]
var s = rb.value == value;
if (s && ! rb.selected) {
rb.setAttribute('selected', true);
} else if (!s && rb.selected) {
rb.setAttribute('selected', false);
}
}
}
super.setValue(value,isinitvalue);
</method>
</class>
</library>
Cross References
Includes
Classes
Named Instances