Deepak Marur
Deepak Marur

Reputation: 547

ExtJS Textarea - autosave contents on user input

I'm an ExtJS newbie and need to send the contents of a ExtJS Textarea to the backend server for saving (autosave facility) as the user types in. Is there a way to do it. I've currently registered a keyup listener to collect the input value as shown below:

items: [{
    xtype: 'textarea',
    id: 'notes',
    anchor: '100%',
    height: 270,
    msgTarget: 'under',
    fieldLabel: 'Note',
    enableKeyEvents: true,
    listeners: {
        'keyup': function(textarea, event) {
            var v= textarea.getValue();
            Ext.Ajax.request({
                url: 'buffernote.action',
                params: {value: v}
            })
        }
    }
}
}]

Am I in the right direction?

Upvotes: 3

Views: 3034

Answers (2)

Francesco
Francesco

Reputation: 454

If you need a buffer, put some ref to the textarea, then call

this.mon(myTextarea, 'keyup', this.onMyTextareaKeyup, this, {buffer: 1000});

where onMyTextareaKeyup contains the code that you provided to do the request. More info on buffer can be found on API.

Upvotes: 2

sra
sra

Reputation: 23973

You should use two events: one key event and one blur event (blur, change or valid) Then fill a 'key hit' buffer and write the whole field back if full and reset the buffer. Also write the whole field back if the blur event get executed.

Personally I am using stores that do the write & updates actions for me. So I just need to modify a record in the store. For that way you just need to play with record.beginEdit() & record.endEdit() In ExtJS 4.x they are now using the term Ext.data.Model but it behaves much the same as in ExtJS 3.x

The store will need the option autoSave: true otherwise you have to call save() on the store to submit any changes.

Upvotes: 1

Related Questions