Results 1 to 3 of 3

Thread: Boolean field in Model pass false value to view

  1. #1
    Sencha Premium Member
    Join Date
    Jul 2014
    Posts
    2

    Default Boolean field in Model pass false value to view

    Hi all,

    I have a model that has a boolean field :
    Code:
    name: 'boolean_field', 
    type: 'boolean'
    and I have a view that has an item:
    Code:
    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:

    Code:
    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.

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    setValue calls:

    Code:
    me.setRawValue(me.valueToRaw(value));
    where:

    Code:
    valueToRaw: function(value) {
        return '' + Ext.value(value, '');
    },
    The renderer then acts on the rawValue.

    See:

    http://docs.sencha.com/extjs/4.2.1/s...ethod-setValue
    http://docs.sencha.com/extjs/4.2.1/s...hod-valueToRaw
    http://docs.sencha.com/extjs/4.2.1/s...etDisplayValue

    Desirable or not, that's why.

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2014
    Posts
    2

    Default

    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:

    Code:
    valueToRaw: function(value) {
            if (!value && value !== 0) {
                return '';
            } else {
                return value;
            }
    http://docs.sencha.com/extjs/4.2.2/s...hod-valueToRaw

    Ramya.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •