You found a bug! We've classified it as EXTJS-8799 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha Premium Member
    Join Date
    Dec 2012
    Posts
    19
    Vote Rating
    2
    Mark R is on a distinguished road

      2  

    Default Default value in Models for integer-type fields

    Default value in Models for integer-type fields


    It looks like when I create an integer field in a model, and the field has no default value, it's getting set to zero anyway. Example:

    Code:
               Ext.onReady(function() {
                    Ext.define('thing', {
                        extend: 'Ext.data.Model',
                        fields: [
                            {name: 'number_type_without_default_value', type: 'int'},
                            {name: 'number_type_with_undefined_default_value', type: 'int', defaultValue: undefined},
                            {name: 'number_type_with_default_value', type: 'int', defaultValue: 3},
                            {name: 'string_type', type: 'string'}
                        ]
                    });
    
                    var thisThing = Ext.create('thing');
    
                    Ext.create('Ext.panel.Panel', {
                        html: 'number defaults to zero:
                                <span style="color:red;">'+thisThing.get('number_type_without_default_value')+'</span><br>'
                            + 'number with default value "undefined":
                                <span style="color:red;">'+thisThing.get('number_type_with_undefined_default_value')+'</span><br>'
                            + 'number with set default value: '+thisThing.get('number_type_with_default_value')+'<br>'
                            + 'string defaults to empty text: '+thisThing.get('string_type')+'<br>',
                        renderTo: Ext.getBody()
                    });
                });
    But the documentation at http://docs.sencha.com/ext-js/4-1/#!...g-defaultValue says "Defaults to: """ and "May be specified as undefined to prevent defaulting in a value." Neither of these seems to be working for me. For each of the first two cases, I get 0.

    I'm using version 4.1.3.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Thanks for the report! I have opened a bug in our bug tracker.

  3. #3
    Sencha Premium Member
    Join Date
    Dec 2012
    Posts
    19
    Vote Rating
    2
    Mark R is on a distinguished road

      0  

    Default


    Thanks.

    The workaround I used was to just reset the values of the affected fields immediately after the create statement -- here's the actual code I used in the project I'm working on:

    Code:
            var newRecord = Ext.create(modelName, {
              action: 'create'
            });
            Ext.each(['pt_id', 'cds_id'], function(fieldName) {
              newRecord.data[fieldName] = null
            });

Thread Participants: 1