baseform.lzx
<library>
<class name="baseform">
<attribute name="formdata"/>
<attribute name="changed" value="false
" setter="this.setChanged(changed, false)"/>
<event name="onchanged"/>
<method name="construct" args="parent, args">
super.construct(parent, args);
this.formdata = {};
</method>
<method name="addFormItem" args="item">
var base = item.name;
if (base == null) base = "$noname"
var itemname = base;
var count = 1;
while (this.formdata[itemname]) {
itemname = base + count++;
}
this.formdata[itemname] = item;
</method>
<method name="removeFormItem" args="item">
for (var name in this.formdata) {
if (this.formdata[name] == item) {
delete this.formdata[name];
}
}
</method>
<method name="setChanged" args="changed,skipformdata">
// This is being set with default value, which should be false.
if (! isinited) {
this.changed = false;
return;
}
var oldchanged = this.changed;
this.changed = changed;
// if we got notified about a reset check if we are complete in
// original state
if(!changed && skipformdata && this['formdata']){
var fd = this.formdata;
for(var k in fd){
if(fd[k].changed){
// still something in changed state...
this.changed = true;
break;
}
}
}
// set formdata all to unchanged if changed is set to false.
if (! changed && ! skipformdata && this['formdata'] ) {
var fd = this.formdata;
for (var k in fd) {
fd[k].setChanged(false, true);
}
}
// Only send changed event if it wasn't changed before.
if (this.changed != oldchanged) {
if (this.onchanged) this.onchanged.sendEvent(this.changed);
}
</method>
<method name="rollback">
if (! this.changed) return;
if (this['formdata']) {
var fd = this.formdata;
for (var k in fd) {
fd[k].rollback();
}
}
this.setChanged(false, true);
</method>
<method name="commit">
if (! this.changed) return;
if (this['formdata']) {
var fd = this.formdata;
for (var k in fd) {
fd[k].commit();
}
}
this.setChanged(false, true);
</method>
<doc>
<tag name="shortdesc"><text>web form</text></tag>
<text>
<p>The <tagname>baseform</tagname> tag allows you to create a web
form. The data represented by components that are enclosed in the
form tag can be sent to the server using the <sgmltag class="element" role="lz.submit"><submit></sgmltag>
tag. Each form component, such as <sgmltag class="element" role="lz.checkbox"><checkbox></sgmltag>,
<sgmltag class="element" role="lz.combobox"><combobox></sgmltag> or <sgmltag class="element" role="lz.radiogroup"><radiogroup></sgmltag> must have
a name. The data is submitted as name-value pairs, using the name and
value of the component.</p>
<p><classname>baseform</classname> provides no layout for its
contents. If you want a simple automatic form layout use the
<sgmltag class="element" role="lz.form"><form></sgmltag> tag.</p>
<p><b>See Also:</b></p>
<ul>
<li>
<sgmltag class="element" role="lz.form"><form></sgmltag> and <sgmltag class="element" role="lz.submit"><submit></sgmltag>
</li>
<li>Form components:
<sgmltag class="element" role="lz.checkbox"><checkbox></sgmltag>, <sgmltag class="element" role="lz.radiogroup"><radiogroup></sgmltag>,
<sgmltag class="element" role="lz.combobox"><combobox></sgmltag>, <sgmltag class="element" role="lz.button"><button></sgmltag>,
<sgmltag class="element" role="lz.edittext"><edittext></sgmltag>, and <sgmltag class="element" role="lz.list"><list></sgmltag>
</li>
</ul>
</text>
</doc>
</class>
</library>