Results 1 to 2 of 2

Thread: Date not being passed to functions in Ext.Date.formatFunctions

    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2968 in a recent build.
  1. #1
    Ext JS Premium Member
    Join Date
    Nov 2009
    Posts
    233
    Vote Rating
    2
      0  

    Default Date not being passed to functions in Ext.Date.formatFunctions

    I'm trying to add some custom date formatters to be used inside of XTemplates, and according to the API documentation for Ext.Date.formatFunctions, custom formatting functions added to this object will be passed the date to be formatted as an argument.

    This doesn't actually appear to be the case, since the underlying code that calls the format function looks like:

    Code:
    /**
     * Formats a date given the supplied format string.
     * @param {Date} date The date to format
     * @param {String} format The format string
     * @return {String} The formatted date
     */
    format: function(date, format) {
        if (utilDate.formatFunctions[format] == null) {
            utilDate.createFormat(format);
        }
        var result = utilDate.formatFunctions[format].call(date);
        return result + '';
    },
    So the custom formatter is actually being called in the scope of the date instead of it being passed as a parameter. Are the API docs just wrong or something?

    Here's a little example:

    Code:
    Ext.Date.formatFunctions['customFormat'] = function() { console.log(arguments); console.log(this); return 'test'; }
    
    
    (new Ext.XTemplate('date: {start:date("customFormat")}')).apply({ start: new Date() });
    You'll see the arguments of the function are empty, but the scope is of the Date object to be formatted.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    Simple documentation update. The date can be resolved by the scope.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Posting Permissions

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