PDA

View Full Version : validation disable button



bauchinj
1 Dec 2009, 6:48 AM
Hello!

Don't know, how to disable a button, when a field of form isn't valid!

Had tested following:


layout : 'form',
monitorValid: true,
items : [{...}]

--------------------------

xtype : 'button',
formBind: true,
scope : this
It's a bit complicated to explain, because first part is in center region and second on east region of borderlayout! I still haven't found another valuation...

PS: I also don't find formBind in doc

Animal
1 Dec 2009, 8:50 AM
You have to listen for the FormPanel's clientvalidation event, and in the listener, set the Button's disabled state accordingly.

bauchinj
4 Dec 2009, 1:45 AM
How to listen?

I tried following:


Ext.getCmp('baseconfigurationForm').clientvalidation({
????
});

Am I able to use this? My button now haven't an ID, is this a problem?

Animal
4 Dec 2009, 2:20 AM
Event?

bauchinj
4 Dec 2009, 2:22 AM
Ext.getCmp('baseconfigurationForm').on({'clientvalidation':test, scope:this});

???

Animal
4 Dec 2009, 2:39 AM
And? Your function test.

What does it do?

bauchinj
4 Dec 2009, 2:56 AM
Thank you for your help animal!

Here is my solution:

Ext.getCmp(field).addListener('change',function(){
if(Ext.getCmp(field).isValid()){
Ext.getCmp(button).setDisabled(false);
}
else{
Ext.getCmp(button).setDisabled(true);
}
});

Maybe it's not the finest, but it work ;)

Animal
4 Dec 2009, 3:02 AM
Well, if it's only one field, that's fine.

If it's the whole form which has to be valid, you need to use the clientvalidation event of the FormPanel.