Hemant
Hemant

Reputation: 83

How to solve this error "Uncaught TypeError: Cannot call method 'getForm' of undefined "

I tried to add edit button functionality in grid panel. I want to open an edit window on edit button click for updating grid row record using Ext Window Form which contains fields like (Shift Name, Time, Total, Requirement, Note). The window form is created, but the row values that I have selected in grid are not set in form fields.

I tried to use this code:

Ext.getCmp('shiftWindow').getForm().setValues(selection[0].data);

but it's giving the following error

Uncaught TypeError: Cannot call method 'getForm' of undefined

Here is my code:

var shiftWindow = Ext.create('Ext.window.Window', {
    title: 'Edit Shift',
    resizable: false,
    id: 'shiftwindow',
    width: 465, //bodyPadding: 5, modal: true, store: shiftStorePlanner,

    items: {
        xtype: 'form',
        id: 'idFormShift',
        bodyPadding: 10,
        items: shiftViewModelPlannerData
    },
    buttons: [{
        text: 'Save',
        cls: 'planner-save-button',
        overCls: 'planner-save-button-over',
        handler: function () {
            var wi = this.up('.window')
            var form = Ext.getCmp('idFormShift');
            if (form.isValid()) {
                shiftTimemappingarray = [];
                getShiftTime();
                //this.up('.window').close();
            }
        }
    }, {
        text: 'Cancel',
        handler: function () {
            this.up('.window').close();
        }
    }]
});

var host1 = Ext.getCmp('plannershifteditor');
var selection = host1._shiftPlannerGrid.getSelectionModel().getSelection();
if (selection.length === 0) {

    return;
}
selection[0].data.ShiftName = selection[0].data.ShiftName.replace('(ARCHIVED)', '').trim(); //if edit Archive record then text name show without (ARCHIVED)

//shiftWindow.getForm().setValues(selection[0].data);
Ext.getCmp('shiftWindow').getForm().setValues(selection[0].data);
//Ext.getCmp('shiftWindow').setValue(selection[0].data);

shiftWindow.show();

Upvotes: 0

Views: 471

Answers (1)

Bretch Guire Garcinez
Bretch Guire Garcinez

Reputation: 219

There's no getForm method in the window. You can get the form using shiftWindow.down('form'). Here's the snippet:

shiftWindow.down('form').form.setValues(selection[0].data)

Upvotes: 1

Related Questions