No announcement yet.
  • Filter
  • Time
Clear All
new posts

  • ValuesManager.valuesHaveChanged and nested arrays with dates

    SmartGWT 4p nightly; SmartClient Version: v9.0p_2014-01-01/LGPL Development Only (built 2014-01-01)
    Chromium Version 31.0.1650.63 Ubuntu 12.04 (31.0.1650.63-0ubuntu0.12.04.1~20131204.1)

    I have a data source that contains an array of nested objects that contain dates.


    {id: 1,
     name: "parentObject",
     items: [{id: 1, name: "nested", effectiveDate=Mon Jan 20 12:00:00 GMT-500 2014},
             {id: 2, name: "another nested object", effectiveDate=Mon Jan 20 12:00:00 GMT-500 2014}]}
    Calls to ValuesManager.valuesHaveChanged() always returns true, even if no changes were made. I tracked down the cause to the following in ISC_Forms.js:

    compareValues : function (value1, value2) {
        if (value1 == value2) return true;
        if (isc.isA.Date(value1) && isc.isA.Date(value2))
            return (Date.compareDates(value1, value2) == 0);
        else if (isc.isAn.Array(value1) && isc.isAn.Array(value2)) {
            if (value1.length != value2.length) return false;
            for (var i = 0; i < value1.length; i++) {
                if (!isc.DynamicForm.compareValues(value1[i], value2[i])) return false;
            return true;
        } else {
            // handle having values set to Number, String etc instance
            // IE var foo = new Number(2); rather than just var foo = 2;
            // This returns true for isA.Object()
            if (isc.isA.Number(value1) || isc.isA.String(value1) || isc.isA.Boolean(value1)) {
                value1 = value1.valueOf();
            if (isc.isA.Number(value2) || isc.isA.String(value2) || isc.isA.Boolean(value2)) {
                value2 = value2.valueOf();
            if (value1 == value2) return true;
            if (isc.isAn.Object(value1) && isc.isAn.Object(value2)) {
                var tempObj = isc.addProperties({}, value2);
                for (var attr in value1) {
                    // We're doing a simple == comparison here - won't handle
                    // complex (Object, Date, Array) attribute values
                    if (value2[attr] != value1[attr]) return false;  <-- this line here
                    delete tempObj[attr];
                // tempObj should now be empty if they match
                for (var attr in tempObj) {
                    return false;
                return true;
        return false;
    For some reason SC only does a primitive != comparison for objects in a nested array. If I change this to the following:

                    if (!isc.DynamicForm.compareValues(value1[attr], value2[attr])) return false;
    then it appears to work correctly. Can you explain the reason for this?

  • #2
    We agree that this would indeed cause problems with your usage, and it looks like it is safe to perform a recursive comparison as you suggest.
    We are enabling this in mainline - please try the next nightly build dated Jan 31 or above, 4.1d branch

    Isomorphic Software