Leron
Leron

Reputation: 9856

ExtJS 4 cant check if variable is undefined and alert for error

I have:

dockedItems: [{
                xtype: 'toolbar',
                store: 'RecordsListStore',
                selModel: {
                    selType: 'cellmodel'
                },

and a couple of icons like this:

},{
                    icon: g_settings.iconUrl + 'view-icon.png',
                    text: 'View',
                    itemId: 'view-selected-record-from-grid',
                    scope: this
                },{

This is in my view, and in my controller I have a function which is triggered like this:

'#view-selected-record-from-grid' : {
                click: this.onViewRecordClick
            }

The problem is that I want to show an alert msg. if the user clicks the button when nothing is selected. In my function I get the info for the selected item (if there is any) like so:

onViewRecordClick: function()   {
        /**
     *Getting the id of the record from the selected row
     */
        var id = this.getRecordsListGrid().getSelectionModel().getCurrentPosition().row;
        var rec = Ext.data.StoreManager.lookup('RecordsListStore').getAt(id);
        rec = rec.data.id;

and after that I call my Ajax request, so between those two parts I want to check the values and if they are undefined (the icon is clicked without selection) to alert the user for this. However if I just try this:

if(id == undefined) { alert('No selection');}

and click the icon when nothing is selected I don't get the alert message but instead get an error in the console that

this.getRecordsListGrid().getSelectionModel().getCurrentPosition().row; is undefined

and that's all. I try some things to bypass this issues because as it seems, the functions stops the time it sees an undefined variable, but still can't find an working solution.

Thanks

Leron

Upvotes: 0

Views: 3435

Answers (1)

sha
sha

Reputation: 17860

Check if getCurrentPosition() returns undefined.

Upvotes: 1

Related Questions