Hi,
I think I am maybe missing some steps before invoking focusInItem and/or getSelectionRange. The btn2 getSelectionRange part of the code below does not work in IE; it always return null selection range.
Software:
-SmartGWT 2.4
-GWT 2.1.1
-IE 8, FireFox 3.6.6 and Chrome 8.0.552.237 browsers
Test_focus.html
Test_focus.gwt.xml
Test_focus.java
Could anyone please provide advise on what I need to add or remove from my code?
Is this an IE-related bug?
Thanks,
rtsan
I think I am maybe missing some steps before invoking focusInItem and/or getSelectionRange. The btn2 getSelectionRange part of the code below does not work in IE; it always return null selection range.
Software:
-SmartGWT 2.4
-GWT 2.1.1
-IE 8, FireFox 3.6.6 and Chrome 8.0.552.237 browsers
Test_focus.html
Code:
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<link type="text/css" rel="stylesheet" href="Test_focus.css">
<title>Test Focus</title>
<script> var isomorphicDir = "test_focus/sc/"; </script>
<script type="text/javascript" language="javascript" src="test_focus/test_focus.nocache.js"></script>
</head>
<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
</body>
</html>
Code:
<?xml version="1.0" encoding="UTF-8"?> <module rename-to='test_focus'> <inherits name='com.google.gwt.user.User'/> <inherits name='com.smartgwt.SmartGwt'/> <inherits name="com.smartclient.theme.enterprise.EnterpriseResources"/> <entry-point class='au.com.company.client.Test_focus'/> <source path='client'/> <source path='shared'/> </module>
Code:
package au.com.company.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
public class Test_focus implements EntryPoint
{
DynamicForm form = new DynamicForm();
TextItem fld1 = new TextItem("field1", "Field 1");
TextItem fld2 = new TextItem("field2", "Field 2");
TextAreaItem fld3 = new TextAreaItem("field3", "Field 3");
ButtonItem btn1 = new ButtonItem("btn1", "Set Focus on Field 3");
ButtonItem btn2 = new ButtonItem("btn2", "getSelectionRange");
ButtonItem btn3 = new ButtonItem("btn3", "setSelectionRange");
public void onModuleLoad()
{
fld1.setValue("3");
fld2.setValue("8");
fld3.setValue("This is a test sentence.");
btn1.setColSpan(2);
btn1.addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent aEvent)
{
// Works in IE, Chrome and Firefox.
form.focusInItem("field3");
}
});
btn2.setColSpan(2);
btn2.addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent aEvent)
{
form.focusInItem("field3");
int [] selectionRange = fld3.getSelectionRange();
// IE always return null.
if (selectionRange == null)
{
SC.say("Debug", "selectionRange is null.");
return;
}
// Chrome and Firefox return correct values.
SC.say("Debug", "selectionRange [0]= " + selectionRange [0] + ", selectionRange [1]= " + selectionRange [1]);
}
});
btn3.setColSpan(2);
btn3.addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent aEvent)
{
String v1 = (String) fld1.getValue();
String v2 = (String) fld2.getValue();
// Works in IE, Chrome and Firefox.
form.focusInItem("field3");
fld3.setSelectionRange(Integer.parseInt(v1), Integer.parseInt(v2));
}
});
fld3.addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent aEvent)
{
// Works in IE, Chrome and Firefox.
int [] selectionRange = fld3.getSelectionRange();
SC.say("Debug", "selectionRange [0]= " + selectionRange [0] + ", selectionRange [1]= " + selectionRange [1]);
}
});
form.setFields(fld1, fld2, fld3, btn1, btn2, btn3);
form.setAutoFocus(true);
form.draw();
}
}
Is this an IE-related bug?
Thanks,
rtsan
Comment