PDA

View Full Version : Setting focus on textfield after clicking on checkbox



gnaigaonkar
22 Jun 2009, 9:57 AM
Hello,

I was trying to set focus on a TextField after I have checked a CheckBox. Although I tried using focus(), it does seem to be working.

The TextField is basically a search field which provides a live search as you type in it. However, whenever the checkbox is checked, after I type in a character in the textfield, it loses focus amd I have to again click on the field to enter text.

Lemme know if someone can help.

jadrake75
25 Jun 2009, 9:26 AM
Have you tried putting the focus inside a DeferredCommand invoked on the click of the checkbox? Not sure if this is the solution, but I do know there is timing issues here.

-Jason

gnaigaonkar
30 Jun 2009, 5:16 AM
I have tried that actually. I have tried using focus() at many places but it doesn't seem to work.

The thing is, since am doing a live search, I search for and display results in a grid as every character is typed into the textfield. As soon as I enter any character, the corresponding data is fetched and displayed in the grid. However, this is where I lose focus of the textfield and hence to enter next character I have to again select the textfield and then enter next character.

The_Jackal
9 Aug 2009, 4:30 PM
I had this problem - I had fields in a form in a window, opened from another window (don't ask!).

The first time I clicked in any field the cursor would appear for a second and then disappear - I was losing focus. This meant that fields required two clicks and combo boxes reqired three clicks if they were the first field clicked on a form. If I clicked on the window first, but not in a field then I could click in fields.

I fixed it by using a deferred command to show, focus and toFront the window.

public void showWindow() {
DeferredCommand.addCommand(new Command() {
public void execute () {
configWindow.show();
configWindow.focus();
configWindow.toFront();
}
});
}

Maybe you can call a deferred focus on your panel?

Carl

gnaigaonkar
11 Aug 2009, 8:28 AM
Thnx jadrake75 and The_Jackal..

Using DeferredCommand did help me..I used it after the Grid was loaded with data and that helped me to get focus back to the TextField..Thnx again..

troyg
13 Aug 2009, 12:56 PM
Using the DeferredCommand also worked for me, where I use it after updating the store for a grid.

It's a shame we have to resort to this kind of solution. It would be nice if the grid didn't steal focus.

I saw the Ext JS library had a similar problem, and the bug got fixed.
http://extjs.com/forum/showthread.php?t=43464

micgala
31 Aug 2009, 1:17 AM
Hi.

I am also interested that grid data updates do not steal the focus...

micgala
31 Aug 2009, 1:26 AM
hmm.

Found this: http://www.extjs.com/forum/showthread.php?t=73987

Since I cannot post there:
Is there any side effect on removing the focus?

This could be made configurable in the View... or even removed...

Arno.Nyhm
31 Aug 2009, 3:11 AM
hmm.

Found this: http://www.extjs.com/forum/showthread.php?t=73987

Since I cannot post there:
Is there any side effect on removing the focus?

This could be made configurable in the View... or even removed...


yes it should be configurable ....


i see there a "focusEnabled" but this can not set from outside :-(


possible patch for this ( not testet) :


public class GridView extends BaseObservable {

// ...

protected void refreshRow(int row) {
ModelData m = ds.getAt(row);
if (m != null) {
// do not change focus on refresh
// handles situation with changing cell value with field binding
boolean currentFocusEnabled = focusEnabled; // <--- new line
focusEnabled = false;

insertRows(ds, row, row, true);
getRow(row).setPropertyInt("rowIndex", row);
onRemove(ds, m, row + 1, true);

renderWidgets(row, row);

GridEvent<ModelData> e = new GridEvent<ModelData>(grid);
e.setRowIndex(row);
e.setModel(ds.getAt(row));
fireEvent(Events.RowUpdated, e);
// focusEnabled = true; <-- removed
focusEnabled = currentFocusEnabled; // <-- changed to
}
}

// ...


// new getter and setters
public void setFocusEnabled(boolean focusEnabled){
this.focusEnabled = focusEnabled;
}

public boolean getFocusEnabled(){
return focusEnabled;
}
}

micgala
2 Sep 2009, 3:37 AM
hmm.

Found this: http://www.extjs.com/forum/showthread.php?t=73987

Since I cannot post there:
Is there any side effect on removing the focus?

This could be made configurable in the View... or even removed...

Is it possible that GXT team makes it configured wheter the GridView will perform the focus operation?

This would be much better then having to extend GridView, for one reason (at least):
Everytime a new release of GXT is released we have to check that there were no changes in that method...

I ask you guys, please make this configurable :D

Regards,
Michel.

Arno.Nyhm
2 Sep 2009, 3:53 AM
this not works because focusEnabled is private and not protected :s


public class ExtendedGridView extends GridView {

@Override
protected void refreshRow(int row) {
boolean currentFocusEnabled = focusEnabled;
focusEnabled = false;
super.refreshRow(row);
focusEnabled = currentFocusEnabled;
}

public void setFocusEnabled(boolean focusEnabled) {
this.focusEnabled = focusEnabled;
}

public boolean getFocusEnabled() {
return focusEnabled;
}
}

micgala
2 Sep 2009, 3:59 AM
Arno, this is not the right method.

The one method that needs to be overidden (for now) is:
insertRows

Arno.Nyhm
2 Sep 2009, 4:34 AM
why?

the idea is to use the focusEnabled variable. and then grid.setFocusEnabled(false);

the method i overwrite in the previous post is just to remember the focus enabled setting for this method. and not to implement the functionality.


call order:


protected void insertRows(ListStore<ModelData> store, int firstRow, int lastRow, boolean isUpdate) {

// ... some insert row magic

focusRow(firstRow);
}

//...

public void focusRow(int rowIndex) {
focusCell(rowIndex, 0, true);
}

// ...


public void focusCell(int rowIndex, int colIndex, boolean hscroll) {
Point xy = ensureVisible(rowIndex, colIndex, hscroll);
if (xy != null) {
focusEl.setXY(xy);
if (focusEnabled) { //<----- here is focusEnabled used
focusGrid();
}
}
}

pourmo
3 Sep 2009, 3:16 AM
Hi

There is a lot of discussion here on focus, does anyone know how I can force a component to loose its focus to the next widget on the panel.

Regards
Mo

The_Jackal
6 Sep 2009, 7:11 PM
A quick thought:

You can set the focus of a component - so if you have all your components in a list you can get the next one and call focus()

Carl

pourmo
8 Sep 2009, 3:53 AM
Hi

Yes, this pretty much what I had thought about too. Coming from a Java Swing background, I'm going to implement a FocusPolicy concept, which more or less does what you have mentioned.

Thanks for your feedback.
Mo