View Full Version : SelectField does not allow selection of items with value of 0

11 Nov 2011, 7:43 AM
Sencha Touch version tested:


using custom css but not related to bug
Platform tested against:

iOS 4

There is a bug in the setValue method of Ext.form.Select that prevents selection of items that have a value of 0.

Test Case:

options:[{text:'First Option', value:2},
{text:'Second Option', value: 1},
{text:'Third Option', value:0}

Possible fix:
The problem is that in the setValue method there is code that checks if a value has been passed. It treats undefined, null, and 0 the same. It looks like this:

if (value) {
idx = this.store.findExact(this.valueField, value)
record = this.store.getAt(idx);

The follow override fixes the issue:

Ext.override(Ext.form.Select, {
setValue: function(value) {
var idx = 0,
hiddenField = this.hiddenField,
record, pickerValue;

if ((null !== value) && (undefined !== value)) {
idx = this.store.findExact(this.valueField, value);
record = this.store.getAt(idx);

if (record && this.rendered) {
this.fieldEl.dom.value = record.get(this.displayField);
this.value = record.get(this.valueField);
if (hiddenField) {
hiddenField.dom.value = this.value;
} else {
if (this.rendered) {
this.fieldEl.dom.value = value;
this.value = value;

// Temporary fix, the picker should sync with the store automatically by itself
if (this.picker) {
pickerValue = {};
pickerValue[this.name] = this.value;

return this;

11 Nov 2011, 10:47 AM
Same problem here. Just ran into this problem today. Instead of outputting 0 it just output the value of the option above it, which was like 145 or something. This is a weird bug.

Thanks for providing a temporary workaround, it kind-of solves the problem. It outputs an empty string '' instead of 0. See code below.

xtype: 'selectfield',
fieldLabel: 'All schedule types',
displayField: 'text',
valueField: 'value',
width: 200,
store: app.stores.ScheduleType,
listeners: {
change: function(o, value, e){
console.log(value) // outputs '' empty string instead of '0'

Looking forward to getting this fixed :)

21 Nov 2011, 2:15 PM
I just found another piece that was missing. We need one more override to allow a field to be initialized with a value of 0. (without this override, any field that is set to 0 by default or by loading values into the form will have the value changed to '' behind your back). The problem is that the code for setting the value tests for the truthiness of the value and if it is false, then it sets it to ''.

Ext.override(Ext.form.Field, { initValue: function() {
var value = (Ext.isEmpty(this.value) ? '' : this.value);
this.setValue(value, true);

this.originalValue = this.getValue();