-
8 Jan 2013 6:40 AM #1
SetSelectionRange doesn't work
SetSelectionRange doesn't work
Hello,
it's not possible to set the selection of a ValueBaseField (GXT 3.0.1, Firefox 10.0.6/Internet Explorer 9).
So here's an example:
In Firefox the selection doesn't change at all, in Internet Explorer the cursor is beeing moved to the first position.Code:public class GXT_3_0 implements EntryPoint { public void onModuleLoad() { RootPanel.get().add(createMainPanel()); } private Container createMainPanel() { VerticalLayoutContainer vlc = new VerticalLayoutContainer(); vlc.setBorders(true); vlc.setPixelSize(600, 400); final TextField field = new TextField() { // { // impl = GWT.create(MooTextBoxImpl.class); // } }; field.setValue("test string"); vlc.add(field); final TextButton button = new TextButton("clickMe"); button.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { field.focus(); field.setSelectionRange(2, 5); } }); vlc.add(button); return vlc; } }
This happens because you're calling the javascript method 'setSelectionRange' on a div container and not the input element itself as it is intended:
https://developer.mozilla.org/en-US/...SelectionRange
Try my commented out code and add MooTextBoxImpl:
The first message returns "x-widget-1", the grandparent of the input element. The second message returns the following exception: "TypeError: elem.setSelectionRange is not a function".Code:public class MooTextBoxImpl extends TextBoxImpl { public MooTextBoxImpl() { } public native void setSelectionRange(Element elem, int pos, int length) /*-{ window.alert(elem.id); // x-widget-1, which is the grandparent node of the actual input element // elem = elem.firstChild.firstChild; // this 'fix' works just fine try { elem.setSelectionRange(pos, pos + length); } catch (e) { window.alert(e); // let's show the exception here } }-*/; }
If you add my commented out line, everything works just fine. It's not really a fix, but it shows you where the problem lies. Hopefully you can fix this one soon.
-
8 Jan 2013 11:30 AM #2
TextBoxImpl is the specific code run for each browser - if there is a bug, it is in the GXT classes that try to use it, and how they are invoking it.
In this case, ValueBaseField has a bug - in its setSelectionRange(int,int) method, it should be passing getInputEl() into impl.setSelectionRange, not getElement(). A fix for this was committed on Nov 2nd, and appears to be present in 3.0.3. Can you confirm that this works in 3.0.3?
Your fix may work as a workaround, but is a little sketchy, as this may break other classes like the GWT TextBox or TextArea. Another idea could be to do your try/catch, but in the catch, reassign elem to elem.firstChild.firstChild, and try again. This, by the way, is what getInputEl() does - it asks the cell to get the input element, the cell asks the appearance, and the appearance invokes parent.getFirstChildElement().getFirstChildElement().
-
9 Jan 2013 1:50 AM #3
Yeah, as I wrote it is a really dirty fix. For now I'm using my TextBoxImpl implementation only for one TextField subclass, so it won't break anything else.
Wow, that sound's great! How can I access the 3.0.3 version? I can't even access the 3.0.2 release (do I have a "Sencha support subscription" as a "Sencha premium member"? My login data doesn't seem to work there..). I would be grateful for a short message.
-
9 Jan 2013 11:11 AM #4
You've got the "Sencha Premium Member" tag under your name, so I assume that you've got access to https://support.sencha.com/ - nightly builds and support releases are available there as well as support tickets. If you don't have access to that, send an email to your sales person, or send me an email at colin.alworth@sencha.com.
-
10 Jan 2013 1:32 AM #5
Now I could log in successfully, thanks!
I will update this bug report after testing 3.0.3.
-
17 Jan 2013 6:51 AM #6
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote