-
12 Nov 2007 9:24 AM #1
Binding a Button's disabled/enabled state to a Form's validity state
Binding a Button's disabled/enabled state to a Form's validity state
So I want my submit button to be enabled/disabled depending on the form's validity status. For example,
It seems the button's disabled property does change, but changing the property doesn't re-render the button.Code:var registerButton = new Ext.Button({ text: 'Register', handler: function() {}, disabled: true }); var firstnameField = new Ext.form.TextField({ fieldLabel: 'First Name', name: 'firstname', allowBlank: false }); firstnameField.on('change', function() { registerButton.setDisabled(!formPanel.form.isValid()); }); var secondnameField = new Ext.form.TextField({ fieldLabel: 'Second Name', name: 'secondname', allowBlank: false }); var formPanel = new Ext.FormPanel({ region: 'center', title: 'Register Form', labelWidth: 80, frame: true, defaults: {width: 200}, items: [firstnameField, secondnameField], buttons: [registerButton] }); new Ext.Viewport({ layout: 'border', items: formPanel });
-
12 Nov 2007 9:34 AM #2
This functionality is already built into the Form - you don't have to code it yourself. Add formBind:true to the button config for any buttons in the form you want to manage. Then after creating the form, call form.startMonitoring(). This will check the form's validity on a timer and enable/disable the buttons. You should call form.stopMonitoring() before actually submitting so the timer doesn't continue to run.
Tim Ryan
Read BEFORE posting a question / BEFORE posting a Bug
Use Google to Search - API / Forum
API Doc (4.x | 3.x | 2.x | 1.x) / FAQ / 1.x->2.x Migration Guide / 2.x->3.x Migration Guide
-
12 Nov 2007 11:11 AM #3
Job's a good'un
Job's a good'un
Every day's a school day. Thanks.


Reply With Quote