1
votes

Please check this fiddle. I am pasting some value in ExtJs 4.1 textareafield but I am not able to the value of the field. Please suggest the ways get the value in the paste event.

Ext.onReady(function () {
    Ext.create('Ext.window.Window', {
        height: 60,
        layout: 'anchor',
        minHeight: 60,
        width: 200,
        items: [{
            grow: true,
            anchor: '100%',
            flex: 1,
            enableKeyEvents: true,
            xtype: 'textareafield',
            id: 'txtFld',
            listeners: {
                keydown: function (txtArea, e, eOpts) {
                    //console.log(e.getKey());
                    if (e.keyCode == 13 && txtArea.value.split("\n").length >= 5) {
                        console.log('unable to stop :( ');
                        e.stopEvent();
                        return false;
                    }
                },
                paste: {
                    element: 'inputEl',
                    fn: function (event, inputEl) {

                        if (event.type == "paste") {
                            console.log('in pasted');

                            console.log("inputEl.value >> " + inputEl.value);
                            console.log("inputEl.innerHTML >> " + inputEl.innerHTML);
                            console.log("inputEl.innerText >> " + inputEl.innerText);
                            console.log("inputEl.outerText >> " + inputEl.outerText);
                            console.log("inputEl.outerText >> " + inputEl.outerText);

                            console.log(' Ext Val >> ' +Ext.getCmp('txtFld').value);

                            //event.preventDefault();
                            //return false;
                        }
                    }
                }
            }
        }]
    }).show();
});
2

2 Answers

0
votes

It seems that the listener runs before the value of inputEl is set. I found a bit dirty workaround but worked for me.

Add delay:1 to the paste listener. It causes that the listener runs 1ms later and that is apparently enough for the value to be set. I've tested in Chrome@Max OS X.

0
votes

As suggested by Saki, I have added delay:1 to paste event. Here is the updated fiddle.