Results 1 to 3 of 3

Thread: Model.set() does not set modified fields

  1. #1
    Touch Premium Member
    Join Date
    Oct 2010
    Posts
    27
    Answers
    1

    Default Model.set() does not set modified fields

    My models (Sencha Touch 1.1.1) aren't marking changed fields.

    Code:
    Ext.regModel('User', { 
        fields: [ 
            {name: 'name', type: 'string'} 
        ] 
    });  
    var user = Ext.ModelMgr.create({ 
         
    }, 'User');  
    console.log('before set: ', user.getChanges());  
    user.set('name', 'Foo');  
    console.log('after set: ', user.getChanges()); 
    This appears to be similar to an Ext JS bug that has been fixed.
    http://www.sencha.com/forum/showthre...odified-fields

  2. #2

    Default Possible Fix

    I was able to get this working by implementing the following changes:


    In the set function of the Stateful class, the currentValue of the field was never obtained. I added the following code:
    Code:
    currentValue = me.get(fieldName);
    just prior to the line:
    Code:
    me[me.persistanceProperty][fieldName] = value;

    Also in the Stateful class, the isEqual method was never implemented. I used the code from Ext JS:
    Code:
    isEqual: function(a, b){
            if (Ext.isDate(a) && Ext.isDate(b)) {
                return a.getTime() === b.getTime();
            }
            return a === b;
        },

    In the constructor of the Model class I needed to initialize the modified attribute to an empty object:
    Code:
    this.modified = {};
    I placed that code just after the this.dirty = false.


  3. #3

    Thumbs up Persist property on Model is still required

    I had the same issue and realized that apart from the changes mentioned above, we still need to add the
    Code:
    persist: true
    property on all fields in the model that we want to track changes for.

    Alternatively, if you want to track all changes, change this line in Stateful class

    Code:
    if (field && field.persist && !me.isEqual(currentValue, value)) {
    To:
    Code:
    if (field && !me.isEqual(currentValue, value)) {
    HTH!

Posting Permissions

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