PDA

View Full Version : on.change for form.Form?



symfony
23 May 2007, 2:13 AM
Is there any eventlistener, which fires, when any field in this form is changed? Something equal like
.on('afteredit', myEvent); for the editable grid?
kind regards

mdissel
23 May 2007, 2:34 AM
I don't know what you want to do in this event, but the SVN version contains
Field.isDirty
Form.isDirty

to track changes inside a form..

Thanks

Marco

symfony
23 May 2007, 4:01 AM
I want to display an Save-Button, when a field in my form was changed. The 'isDirty' function is useful in some cases, but unfortunately not in mine :(..

mdissel
23 May 2007, 4:42 AM
You can add a listener to the "change" event of all the fields.

Thanks

Marco

symfony
23 May 2007, 4:46 AM
Yes, I already know. But thats very complex, because of heaving much fields in my form :-?. But if there aren't anymore possibilities to avoid this, I have to do it that way :(

milanz
19 Dec 2007, 5:29 PM
Has anyone found a better solution? I agree adding an event handler to each field is less then desirable.

Jojo
11 Jan 2008, 11:40 AM
This might be a little off the mark, as you said you don't want to use isDirty(). It may help someone else though...

In the form config, set monitorValid to true, and add a listener for the clientvalidation event. Set trackResetOnLoad if you want to reset the dirty state when a new record is loaded into the form.

My example uses a formPanel:



var formPanel = new Ext.FormPanel({

//other config options...

monitorValid: true,
trackResetOnLoad: true,
listeners: {
'clientvalidation' : {
fn: function(formPanel,isValid){
var saveButton = formPanel.buttons[0];
var isDirty = formPanel.form.isDirty();

//Form must be dirty and also have passed client side validation. Only then do we enable the save button. The extra if statements are there for performance, in case the setDisabled method is expensive.

if(isValid && isDirty){
if(saveButton.disabled) saveButton.setDisabled(false);
}else if(!saveButton.disabled) saveButton.setDisabled(true);
},
scope: this
}
}

//other config options...

});