PDA

View Full Version : Form, setvalues, and dirty Checking



Voyd
30 May 2012, 8:39 AM
I have form with a bunch of fields that the user needs to fill out. One of the requirements is a button to auto fill the fields with default values. I can do this fine, but the form should now be in a dirty state, which it isn't. I do not understand why the form fields aren't dirty, as their "original" values have now changed. Any help would be greatly appreciated.



// on button click
var object = {
fieldone: '1',
fieldtwo : '2'
}
form.getForm().setValues(object);
// form should now be dirty??

scottmartin
30 May 2012, 5:44 PM
The following returns dirty on both the fields and the form:



var panel = Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
width: 350,

mySpecialProp: 'myvalue',

// Fields will be arranged vertically, stretched to full width
layout: 'anchor',
defaults: {
anchor: '100%'
},

// The fields
defaultType: 'textfield',
items: [{
itemId: 'first',
fieldLabel: 'First Name',
name: 'first',
allowBlank: false
}, {
fieldLabel: 'Last Name',
name: 'last',
allowBlank: false
}],

renderTo: Ext.getBody()
});

var fn = panel.down('#first');

var data = {
first: 'First',
last: 'Last'
}

// dirty = false
console.log(panel.getForm().isDirty());
console.log(fn.isDirty());
// update form
panel.getForm().setValues(data);
// dirty = true
console.log(panel.getForm().isDirty());
console.log(fn.isDirty());


Regards,
Scott.