Compare date from combobox with current date

400 views Asked by At

I have a combobox with data from store:

fields: [
    {name: 'name',  type: 'string'},
    {name: 'createDate',  type: 'string'}
]

Field 'createDate' has format "03.05.2015", this combobox outputs only field 'name':

{
    xtype: 'combobox',
    fieldLabel: 'NameText',
    store: 'storeofnames',
    queryMode: 'local',
    displayField: 'name',
    valueField: 'id'
}

I want next:

Combobox output: name + (if date in field createDate >= current date) add in combobox data from 'createDate'.

1

There are 1 answers

0
Baychurin Anton On

You can do this trick: in your model add item like:

{
    name: 'display',
    mapping: function(rec) {
        return rec.name + (new Date(rec.createDate) >= new Date()
            ? ' ' + rec.createDate
            : '');
    }
}

And in your combobox change displayField:

displayField: 'display'