Search code examples
extjsextjs3

ExtJs datepicker listener


I have datefield on my form:

        var intForm = new Ext.FormPanel({
        width: 350,
        autoHeight: true,
        bodyStyle: 'padding: 10px 10px 10px 10px;',
        labelWidth: 70,
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side'
        },items:[{
            xtype:'datefield',
            fieldLabel: 'Выберете дату',
            name: 'intDate',
            anchor:'80%',
            maxValue: new Date(),
            listeners:{
                'change': function(this,newValue,oldValue){
                    alert('newValue');
                }
            }
        }]
    });

But whe i start application i get error:

 SyntaxError: missing formal parameter  

'change': function(this,newValue,oldValue){ 

I cant use listeners when i create datefield like this, i gonna use variable to create datefield?


Solution

  • You have a syntax error, you cannot use this as a parameter name change it to field or any other name

    var intForm = new Ext.FormPanel({
        width : 350,
        autoHeight : true,
        bodyStyle : 'padding: 10px 10px 10px 10px;',
        labelWidth : 70,
        defaults : {
            anchor : '95%',
            allowBlank : false,
            msgTarget : 'side'
        },
        items : [{
            xtype : 'datefield',
            fieldLabel : 'Выберете дату',
            name : 'intDate',
            anchor : '80%',
            maxValue : new Date(),
            listeners : {
                'change' : function(field, newValue, oldValue) {
                    alert('newValue');
                }
            }
        }]
    });