View Full Version : form isDirty() always return true, when using itemselector and loading data for it...

19 Oct 2009, 11:03 PM
I meet an issue about isDirty() and ItemSelector.

There is an itemselector in a form and the data is dynamically loaded to the form fields by ajax (the selected and from store of itemselector will be changed based on loading data). Although'trackResetOnload" is set to true, form.isDirty() always returns true.

Is there something like originalValue of itemselector? If so, after loading, i can manually reset its original value. Or are there any other smart methods to handle it?


6 Jan 2011, 5:49 PM
here is a fix, combined with a fix provided by tungj (http://www.sencha.com/forum/member.php?102093-tungj) (OPEN-1200] Ext.ux.form.ItemSelector leak due to ItemSelector.js line 93/117 (http://www.sencha.com/forum/showthread.php?106965-OPEN-1200-Ext.ux.form.ItemSelector-leak-due-to-ItemSelector.js-line-93-117)) that solves both problems for the itemSelector :)

var origRender = Ext.ux.form.ItemSelector.prototype.onRender;
var origBeforeDestroy = Ext.ux.form.ItemSelector.prototype.beforeDestroy;
Ext.override(Ext.ux.form.ItemSelector, {
beforeDestroy: function(){
origBeforeDestroy.apply(this, arguments);
if (this.rendered) {
// Need to deregister the click listeners otherwise the selector and children will leak
this.toTopIcon.un('click', this.toTop, this);
this.upIcon.un('click', this.up, this);
this.downIcon.un('click', this.down, this);
this.toBottomIcon.un('click', this.toBottom, this);
this.addIcon.un('click', this.fromTo, this);
this.removeIcon.un('click', this.toFrom, this);
onRender: function() {
origRender.apply(this, arguments);
// Want to destroy the panel containing the multiSelects, but it's internal
// so have to access it via ownerCt
var leakPanel = this.toMultiselect.ownerCt;
this.on('destroy', leakPanel.destroy, leakPanel);
afterRender: function(){

this.toStore = this.toMultiselect.store;
this.toStore.on('add', this.valueChanged, this);
this.toStore.on('remove', this.valueChanged, this);

//change for a custiom load not value changed as in original code
this.toStore.on('load', this.valueLoad, this);
valueLoad: function(store) {
var record = null;
var values = [];
for (var i=0; i<store.getCount(); i++) {
record = store.getAt(i);
var valuesToSet = values.join(this.delimiter);
this.hiddenField.dom.value = valuesToSet;
this.originalValue = valuesToSet;