PDA

View Full Version : Change listener in form



medley
7 Sep 2011, 5:22 AM
Hello,

I have a grid and form. When I click on one row of the grid, the form is loaded with the selected record.
1 - When I change the value of one field, I disable the grid (see change event of my controller).
2 - When I click on the button 'Cancel', I reload the form with the selected row of the grid and I enable the grid (function "cancelEditService") . However, after the reload, the event "change" fires and I don't want it to fire.



Ext.define('EPplatosRegistry.controller.Services', {
extend : 'Ext.app.Controller',
...
'serviceedit > textfield': {
change: {
fn: this.textFieldChange,
buffer: 500 // Delay the request by half a second
}
}
});
},
...
cancelEditService : function(button) {
var grid = this.getServiceslist(), record = grid.getSelectionModel().getLastSelected(), form = this.getServiceedit(),toolbar = form.getDockedComponent('buttons'),
saveButton = toolbar.getComponent('save'), cancelButton = toolbar.getComponent('cancel'),
editButton = toolbar.getComponent('edit');
var items = form.items;
var i = 0;
for(i = 0; i < items.length; i += 1){
items.getAt(i).setReadOnly(true);
}
form.loadRecord(record);
grid.enable();
editButton.enable(); saveButton.disable(); cancelButton.disable();
},
...

textFieldChange: function(textField, newValue, oldValue, options) {
var grid = this.getServiceslist(), form = this.getServiceedit(),toolbar = form.getDockedComponent('buttons'),
saveButton = toolbar.getComponent('save'), cancelButton = toolbar.getComponent('cancel'),
editButton = toolbar.getComponent('edit');
if(textField.name != 'revision') {
saveButton.enable();cancelButton.enable();editButton.disable();
grid.disable();
}
}
});


Thanks for help
Medley

jay@moduscreate.com
7 Sep 2011, 10:09 AM
You code is given gem headaches! You should code one command per line.

That said, you can use the removeListner or short hand un() method to remove the event.

You can also suppress the event and resume it.

skirtle
8 Sep 2011, 3:12 AM
Perhaps you could use isDirty() with trackResetOnLoad?

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-isDirty

If the form is dirty you disable the grid, if it isn't then you enable it.

medley
9 Sep 2011, 12:45 AM
I found this property "suspendCheckChange" which can have the value 0 or 1. It works but I don't know if I can use it..

Medley