How to show Moment JS formatted date in ExtJS fiel

2019-09-08 18:41发布

问题:

I have an ExtJS field as:

field = {
    xtype : 'datefield',
    format : 'Y/m/d',
    draggable : true,
    allowBlank : true,
    pickerAlign : 'tr-br',
    getValue : function()
    {
        return this.getRawValue();
    }
};

This works fine and I get the date in the field in the specified format. I want to be able the parse the date coming in from the datepicker and then display the date in locale specific format. How do I do it?

回答1:

field = {
    xtype: 'datefield',
    format: 'Y/m/d',
    draggable: true,
    allowBlank: true,
    pickerAlign: 'tr-br',
    isValid : function()
    {
        return true;
    },
    setValue : function(value)
    {
        var valueToSet = "";
        if (value)
        {
            valueToSet = moment(value).lang(lang + "-" + cntry).format('L');
        }
        this.setRawValue(valueToSet);
    },
    getValue: function () {
        return this.getRawValue();
    }
};