PDA

View Full Version : [NOREPRO] [5.0.1] displayfield's renderer function cannot accept boolean values



cwtuan
13 Oct 2014, 9:46 PM
Ext version tested:

Ext 5.0.1
Browser versions tested against:
Chrome version 38 (windws 7 64bits)

Description:
https://fiddle.sencha.com/#fiddle/bol
var form = Ext.create('Ext.form.Panel', {
title: 'Basic Form',
renderTo: Ext.getBody(),
width: 350,
items: [
{
xtype: 'displayfield',
fieldLabel: 'deleted?',
name: 'deleted',
renderer: function(value) {
console.log('deleted value', value, typeof value);
return value;
}
}]
});
form.getForm().setValues({
deleted: true // false
});
When form set a true value, the displayfields' renderer is executed twice:



deleted value "" string
deleted value true boolean


When form set a false value, the displayfields' renderer is executed twice:



deleted value "" string
deleted value "" string


The result that was expected:
1. The field's renderer function should be executed only once when setting form values.
2. In renderer: function(value), the value should be boolean instead of string if form set a boolean value.

slemmon
13 Oct 2014, 10:34 PM
Hi,

The behavior seems correct.
The renderer is called first when the displayfield is instantiated allowing for the renderer to process the value configured on the displayfield (or even the default value of '').

cwtuan
14 Oct 2014, 5:19 AM
Hi Slemmon,
So why does form.setValues({deleted: false}) result in

deleted value "" string
deleted value "" string


Shouldn't it be like this?

deleted value "" string
deleted value false boolean

cwtuan
15 Oct 2014, 6:28 PM
In Ext 4,
The output would be

deleted value "" string
deleted value false string


It seem there's a bug in Ext 5.

urban.novak
15 Oct 2014, 7:21 PM
Maybe like there was a bug in Ext 4 and they fixed it in Ext 5 :) .

Conversion of value:false to empty string is caused by valueToRaw method, which was not present in Ext4. If you like old Ext4 behaviour more, you can use this override

Ext.define('fixed.Ext.form.field.Display', { override: 'Ext.form.field.Display',
valueToRaw: function(value) {
return value;
}
});

If you use checkbox instead of displayfield, you get correct and consistent behaviour in both Ext4 and Ext5 out of the box.