PDA

View Full Version : Boolean field in Model pass false value to view



ramya.gopalan
23 Jul 2014, 12:37 PM
Hi all,

I have a model that has a boolean field :


name: 'boolean_field',
type: 'boolean'


and I have a view that has an item:


xtype: 'displayfield',
name: 'boolean_field',
renderer: function(value) {
if(value) { return 'Yes'; }
if(!value) {return 'No';}
return '';
}


My problem is the view never gets a false value. So, I always get 'Yes' or ''. However, if I changed the model to pass a string, and handle it in the view renderer as:



renderer:function(value) {
if (value === 'true') { return 'Yes'; }
if (value ==='false') {return 'No'; }
return '';
}

I get Yes/No and empty string.

Can someone tell me why the boolean false is never passed to the view?

Thanks!
Ramya.

skirtle
23 Jul 2014, 2:51 PM
setValue calls:


me.setRawValue(me.valueToRaw(value));

where:


valueToRaw: function(value) {
return '' + Ext.value(value, '');
},

The renderer then acts on the rawValue.

See:

http://docs.sencha.com/extjs/4.2.1/source/Base3.html#Ext-form-field-Base-method-setValue
http://docs.sencha.com/extjs/4.2.1/source/Base3.html#Ext-form-field-Base-method-valueToRaw
http://docs.sencha.com/extjs/4.2.1/source/Display.html#Ext-form-field-Display-method-getDisplayValue

Desirable or not, that's why.

ramya.gopalan
24 Jul 2014, 9:47 AM
Thanks for your response! I still did not know what was changing the boolean "false" value to empty value. Followed your links to figure out that the displayfield's valueToRaw function does this:



valueToRaw: function(value) {
if (!value && value !== 0) {
return '';
} else {
return value;
}


http://docs.sencha.com/extjs/4.2.2/source/Display.html#Ext-form-field-Display-method-valueToRaw

Ramya.