PDA

View Full Version : Does TextField.focus() work ?



gnaigaonkar
7 Jul 2009, 10:41 AM
I am trying to set focus back to a textfield, but it doesn't seem to work. In fact I dont want to lose focus of the textField in the first place.

I am trying to develop a sort of search module and this textfield is part of it which accepts the name to search. There is one filter for the serach and to activate it, one has to check a checkbox. However, as soon as I check the checbox, I lose focus of the textfield. I tried to use textfield.focus() within the clickhandler of checkbox. But it doesnt seem to work.

Lemme know if anyone can help.

sven
7 Jul 2009, 10:43 AM
Try to call focus in a DeferredCommand. I am using focus in many places without problems.

gnaigaonkar
7 Jul 2009, 11:17 AM
I tried using DeferredCommand to set focus on the TextField in this way..



Command cmd = new Command()
{
public void execute()
{
nameField.focus();
}
};

DeferredCommand.addCommand(cmd);



I added this at a number of places, but no effect. With every key press within the TextField, I fire a search. Now, in case the checkbox is checked (to filter the results) and I type into the TextField, the results are displayed in a grid but I lose focus of the textField.