PDA

View Full Version : Simple way to do autocpmlete in textarea



HemantPagare
26 Feb 2009, 9:53 PM
hey this is my code that can be simpler for autocpmlete feature for textarea....



Ext.onReady(function(){
// initialize
Ext.QuickTips.init();
var value="";
var myAutoCombo=new Ext.form.ComboBox({

renderTo :'auto',
fieldLabel: 'Email',
name: 'time1',
id:'myAuto',
store:['hemant@psl.com', 'pravin@asd.co.in', 'yash@gmail.com','sagar@rediff.com'],
editable: true,
forceSelection: false,
hideTrigger: true,
enableKeyEvents:true,
x:20,
y:0,
autoCreate: {tag: 'textarea', style:'width:300;height:60;', autocomplete: 'off'},
width:300,
listeners:{

keyup: function(f,e) {

this.editable=true;
value=Ext.get('myAuto').dom.value;

if (e.getKey() == e.ENTER )
{
Ext.get('myAuto').dom.value=value.substring(0,value.lastIndexOf(';')+1)+this.getValue();
return;
}
},
select:function(f,r,index) {

this.editable=true;
Ext.get('myAuto').dom.value=value.substring(0,value.lastIndexOf(';')+1)+this.el.dom.value;

}

}



} );


myAutoCombo.on('beforequery', function(queryEvent){

if(queryEvent.query.indexOf(';')!=-1){

queryEvent.query=queryEvent.query.substring(queryEvent.query.lastIndexOf(';')+1,queryEvent.query.length);
this.editable=false;
}

});

});

if anybody finds some bugs plz reply

Arno.Nyhm
7 Apr 2009, 5:24 AM
you have some screenshots/demo page?

JasonMichael
7 Apr 2009, 5:37 AM
The one bug I see is that your subject is asking about autocomplete in a textarea, and your code shows an example of how you are setting up a combobox - which has autocomplete working in it, already, with no additional code, as far as I know. If you need autocomplete working in a combobox / select /option, you might be doing something wrong - too much code.
Have you tried the examples?