PDA

View Full Version : Issue registering listener on text box with parameter



himalpatel
7 Sep 2011, 5:19 AM
Hello,
I am using ExtJS 4.
I want to register blur, focus listeneres on a text box. i can do it easily when there is no parameter to the function that I am calling.
Here is the code snap

pnl = Ext.create('Ext.form.Panel', {
title: fldTitle,
labelWidth: 75,
frame: false,
bodyStyle: 'padding:5px 5px 0',
renderTo: Ext.getBody(),
layout: 'auto',
defaults: {
bodyPadding: 4
},
items: [{
xtype: 'fieldset',
autoScroll: true,
flex: 1,
columnWidth: 0.5,
defaultType: 'textfield',
defaults: { anchor: '100%' },
layout: 'anchor',
items: _fields
}],
listeners: alertme


});
function alertme()
{
alert('called');
}


It works fine but when i have some parameter say like

function alertme(msg)
{
alert(msg);
}

i cannot find any way of passing the message.

Thanks you,
Himal

skirtle
8 Sep 2011, 2:21 AM
How do you decide which message to show? Does it depend on which panel it is, or what field it is, or what...?

himalpatel
8 Sep 2011, 8:18 PM
Here I simplified the code.


listeners:'focus':alertme;

so message wil be displayed during focus event, but how can i pass parameter.

Thanks
Himal

skirtle
9 Sep 2011, 1:07 AM
There are many ways to pass a parameter but I can't tell which one will work for you unless you answer my question.


How do you decide which message to show? Does it depend on which panel it is, or what field it is, or what...?

Does the parameter always have the same value or is it dependent on something?

himalpatel
9 Sep 2011, 6:01 AM
No, Parameter will have different value, i am adding listener dynamically. and there it would decide which value to pass. but the number of parameter will remain same.

skirtle
9 Sep 2011, 6:09 AM
i am adding listener dynamically. and there it would decide which value to pass.

This is still a little vague. My best guess based on this description is that you would want something like this:


textbox.on('focus', function() {
alertme('message');
});

or perhaps:


textbox.on('focus', Ext.Function.pass(alertme, ['message']));

himalpatel
9 Sep 2011, 7:24 AM
Yes, tha is what i wad lookong for.
I will give it a try and let you know.

Thanks
Himal