PDA

View Full Version : [FIXED-552]FormPanel setValues method missing setChecked logic & extra values error



VinylFox
13 Nov 2010, 11:46 AM
Sencha Touch version tested:

1.0.0RC

only default ext-all.css


Platform tested against:

Chrome


Description:

The logic for setting the checked status of a checkbox within the setValues method is missing for lone checkboxes.
Calling setValues with extra values that are not represented in the FormPanel throws an error.


Test Case:


Ext.setup({
onReady: function() {
new Ext.form.FormPanel({
fullscreen : true,
autoHeight : true,
dock : 'left',
items: [{
xtype: 'fieldset',
title: 'Project Settings',
items: [{
xtype: 'textfield',
label: 'Name',
name: 'name'
},{
xtype: 'checkboxfield',
label: 'Billable',
name: 'billable'
},{
xtype: 'checkboxfield',
label: 'Enabled',
name: 'enabled'
},{
xtype: 'numberfield',
label: 'Stepping',
name: 'stepping'
},{
xtype: 'numberfield',
label: 'Budget',
name: 'budget'
}],
}],
listeners: {
afterrender: function(frm){
frm.setValues({
name: 'Test Name',
billable: true,
enabled: false,
stepping: 15,
extravalue: 'extra',
budget: 1500
})
}
}
});
}
});

Possible fix:

Check to see that a matching field name actually exists.
Also add logic to call setChecked instead of setValue.
See override.




Ext.override(Ext.form.FormPanel, {
setValues: function(values) {
var fields = this.getFields(),
name,
field;
values = values || {};

for (name in values) {
if (values.hasOwnProperty(name)) {
if (Ext.isArray(fields[name])) {
fields[name].forEach(function(field) {
if (Ext.isArray(values[name])) {
field.setChecked((values[name].indexOf(field.getValue()) != -1));
} else {
field.setChecked((values[name] == field.getValue()));
}
});
} else {
field = fields[name];
// added this wrapping if statement
if (field && field.setChecked){
field.setChecked(values[name]);
}else if (field){
field.setValue(values[name]);
}
// replaces the following line
// field.setValue(values[name]);
}
}
}

return this;
}
});

evant
13 Nov 2010, 10:07 PM
Thanks Shea, a fix has been added.