dojo: How do I connect an onchange event to an entire form?
I'am building a _Widget and I want to attach an onchange event to an entire form, so that as soon as a field of the form is modified, the save button is enabled.
Form in _Template
<form dojoAttachPoint='form'>
<input name='name' >
<button dojoAttachPoint="save">save</button>
</form>
My try in the _Widget
var self=this;
dojo.connect(dijit.byId(this.form), 'onchange' ,function(){
dijit.byId(self.save).setAttribute('disabled', false开发者_JAVA百科);
dojo.disconnect(dijit.byId(self.form));
});
Am I on the wrong track?
You are using dijit.byId
on a non dijit node. You should be using dojo.byId
.
Also, dojo.connect
returns a handler that is what you shoudl use when you call the dojo.disconnect
function.
Thank's again Marcelo.
This now works :)
The modified _Template
<div dojoAttachPoint="sourceForm" dojoType="dijit.form.Form"
encType="multipart/form-data" action="" method="">
<input dojoAttachPoint="name" dojoType="dijit.form.ValidationTextBox"
type="text" name="name" required="true"/>
<button
dojoAttachPoint="save" dojoType="dijit.form.Button"
type="submit" value="Submit" disabled="true">
Save
</button>
</div>
The modified _Widget part
self=this;
dijit.byId(this.save).setAttribute('disabled', true);
var handle= dojo.connect(dojo.byId(this.sourceForm.domNode),'onchange',function()
{
dijit.byId(self.save).setAttribute('disabled', false);
dojo.disconnect(handle);
});
精彩评论