1. #1
    Sencha User
    Join Date
    Jul 2012
    Location
    Italy
    Posts
    84
    Vote Rating
    4
    Answers
    1
    Tegola is on a distinguished road

      0  

    Default Answered: Default value for date fields

    Answered: Default value for date fields


    Hello,
    What's the best way to add the current date to a record field?

    Here's is what was my initial guess:
    Code:
    Ext.define('Message', {
    	extend: 'Ext.data.Model',
    	config: {
    		fields: [
    			{ name: 'id', type: 'int' },
    			{ name: 'title', type: 'string' },
    			{ name: 'body', type: 'string' },
    			{ name: 'created-at', type: 'date', dateFormat: 'Y-m-d H:i:s', defaultValue: new Date() }
    		]
    	}
    });
    However, "new Date()" picks the date when the Model class is instantiated. I would it to pick the date when I do a Ext.create('Message').

    I know I could just do:
    Code:
    Ext.create('Message', { 'created-at': new Date() })
    But I was searching for a way to make sencha do this automatically.

    Thanks

  2. Code:
    constructor:function(){
            var data = arguments[0]||{};
    
    
            data['created-at'] = new Date();
    
            if(arguments.length===0){
                this.callParent([data]);
            }else{
               this.callParent(arguments);
            } 
    }

  3. #2
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Vote Rating
    20
    Answers
    64
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    Code:
    constructor:function(){
            var data = arguments[0]||{};
    
    
            data['created-at'] = new Date();
    
            if(arguments.length===0){
                this.callParent([data]);
            }else{
               this.callParent(arguments);
            } 
    }
    I write English by translator.

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Location
    Italy
    Posts
    84
    Vote Rating
    4
    Answers
    1
    Tegola is on a distinguished road

      0  

    Default


    Thanks!

Thread Participants: 1

Tags for this Thread