Compare date from combobox with current date

I have a summary with data from a store:

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

      

The field 'createDate'

has the format "05/03/2015", this combo box displays only the field 'name'

:

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

      

I want the following:

Combobox output: name + (if the date is in the createDate

>=

current date field ) adds the combobox data from 'createDate'

.

+3


source to share


1 answer


You can do this trick: in your model add an element like:

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

      



And in your displayField combo box:

displayField: 'display'

      

+1


source







All Articles