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
    1
    chinabuffet is on a distinguished road

      0  

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

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Simple documentation update. The date can be resolved by the scope.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1