Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Ext.form.Basic -> getValues

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-21886 in 6.2.1.167.
  1. #1
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751

    Default Ext.form.Basic -> getValues

    hi guys,

    i noticed a change from 6.0.1 to 6.0.2:
    http://docs.sencha.com/extjs/6.0/6.0...thod-getValues
    http://docs.sencha.com/extjs/6.0/6.0...thod-getValues

    the following code got added:
    Code:
    // skipping checkbox null values since they have no contextual value
    if(field.isCheckbox && val===null) {
        continue;
    }
    the change creates a bug for a (in my eyes common) use case, where we use:
    Code:
    form.updateRecord();
    record = form.getRecord();
    
    console.log(record.data);
    in our model definition, the field that matches the checkbox has the type boolean.

    the field definition is just:
    Code:
                                    {
                                        xtype      : 'checkboxfield',
                                        fieldLabel : 'Support Planning Enabled',
                                        name       : 'servicePlanningEnabled'
                                    }
    in case a user checks and unchecks the form and the submit button calls form.updateRecord() afterwards, 6.0.2 always returns true, even when the value should be false. it did work fine in 6.0.1.

    removing the code added to 6.0.2 resolves the issue for us.

    as an shorter override:
    Code:
    Ext.define('Ext.overrides.form.field.Checkbox', {
        override : 'Ext.form.field.Checkbox',
    
        uncheckedValue : false
    });
    also does the trick. according to the docs, uncheckedValue should default to undefined. i did not debug it further to see why we get null instead.

    best regards
    tobi
    Best regards
    Tobias Uhlig

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751

    Default

    just adding:

    Code:
    field.getValue()
    itself for a checkbox returns true and false in the correct way in 6.0.2.
    Best regards
    Tobias Uhlig

  3. #3
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985

    Default

    Thanks for the report. As far as I can tell, those two code files are identical. Any chance you can post a test case which reproduces the issue you are facing?

  4. #4
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,751

    Default

    [EDIT] the urls pointed to a wrong class, fixed the top posting now.

    here the full code as well (marked the part that got added in 6.0.2 in red)

    Code:
        getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues, isSubmitting) {
            var values  = {},
                fields  = this.getFields().items,
                fLen    = fields.length,
                isArray = Ext.isArray,
                field, data, val, bucket, name, f;
    
            for (f = 0; f < fLen; f++) {
                field = fields[f];
                if (!dirtyOnly || field.isDirty()) {
                    data = field[useDataValues ? 'getModelData' : 'getSubmitData'](includeEmptyText, isSubmitting);
    
                    if (Ext.isObject(data)) {
                        for (name in data) {
                            if (data.hasOwnProperty(name)) {
                                val = data[name];
    
                                if (includeEmptyText && val === '') {
                                    val = field.emptyText || '';
                                }
    
                                if (!field.isRadio) {
                                    // skipping checkbox null values since they have no contextual value
                                    if(field.isCheckbox && val===null) {
                                        continue;
                                    }
                                    if (values.hasOwnProperty(name)) {
                                        bucket = values[name];
    
                                        if (!isArray(bucket)) {
                                            bucket = values[name] = [bucket];
                                        }
    
                                        if (isArray(val)) {
                                            values[name] = bucket.concat(val);
                                        } else {
                                            bucket.push(val);
                                        }
                                    } else {
                                        values[name] = val;
                                    }
                                } else {
                                    values[name] = values[name] || val;
                                }
                            }
                        }
                    }
                }
            }
    
            if (asString) {
                values = Ext.Object.toQueryString(values);
            }
            return values;
        }
    let me know in case you have any questions
    Best regards
    Tobias Uhlig

  5. #5
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985

    Default

    Can you not just configure uncheckedValue to false on the checkbox?

  6. #6
    Sencha User
    Join Date
    Apr 2013
    Posts
    914

    Default

    @Gary Schlosberg
    What's the reason behind skipping checkbox value in the first place? Not sure what "no contextual value" supposed to mean.

  7. #7
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,353

    Default

    I just wasted over an hour trying to debug why changes to my boolean values were not being sent to the server. This change is terrible; why should we now have to set an additional property on all our checkboxes if we want a change to its state to actually be picked up elsewhere? Who in their right mind wants a checkbox where a change from checked to unchecked is not recognisable? This is unfathomable.

  8. #8
    Sencha Premium User
    Join Date
    Nov 2013
    Location
    Piacenza, Italy
    Posts
    219

    Default

    Just in case someone else has the same problem, there is also this related issue:
    https://www.sencha.com/forum/showthr....0.2&p=1139725

    In short:
    With Ext JS 6.0.2 the method getModelData() of Ext.form.field.Checkbox has been overriden so that it returns the result of getSubmitValue() (a String) instead of Model data (a Boolean).

    I posted a patch in that thread.

  9. #9
    Sencha Premium Member
    Join Date
    Jan 2016
    Posts
    3

    Default

    Just for the records: this change also breaks using a checkbox in a row editor: the row editor doesn't update the associated record property anymore as it is supposed to do.

    Breaking another part of the framework can't be just waved away with "just update your configs, there's another property been introduced that restores the default behaviour which everybody is used to."

  10. #10
    Sencha Premium User
    Join Date
    Nov 2013
    Location
    Piacenza, Italy
    Posts
    219

    Default

    Hello I saw this in 6.2.1 release notes (http://docs.sencha.com/extjs/6.2.1/g...e_notes.html):
    EXTJS-21886 - Checkboxes don't return the correct value

    This means that this bug has been fixed?
    If so, why this forum thread is still in status "OPEN"?

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 11 Jul 2012, 6:37 AM
  2. [CLOSED] Problem with Form.getValues() after removing a form field.
    By herring80 in forum Ext:Bugs
    Replies: 4
    Last Post: 29 May 2012, 2:09 AM
  3. [FIXED]Ext.form.Basic.getValues()
    By mdavis6890 in forum Ext:Bugs
    Replies: 2
    Last Post: 23 Feb 2011, 8:00 AM
  4. Ext.form.BasicForm.getValues() returns object if form is empty
    By mrutz in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 22 Dec 2009, 2:31 AM

Posting Permissions

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