开发者

dojo: How do I connect an onchange event to an entire form?

开发者 https://www.devze.com 2023-03-28 05:43 出处:网络
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.

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);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消