I've come across an issue where my code behaves fine in Firefox, but differently in Google Chrome and Safari.
I have written code that adds a KeyPressHandler to a FloatItem and looks for a tab. In Firefox this works fine. In Chrome the KeyPressHandler fires for the tab on the field prior to the FloatItem in the form. It doesn't fire when a tab is pressed while focused on the FloatItem itself.
Here is the code (it is attached as well):
My intent here was to allow a user to enter data in a form, tabbing after each field entry to move on to the next. When the user tabs out of the last field, a new row would be added to the form and focus moved there.
Version info:
SmartClient Version: v8.2p_2012-04-10/Enterprise Deployment (built 2012-04-10)
Google Chrome: 18.0.1025.168
Firefox: 11.0
Safari: 5.1
I have written code that adds a KeyPressHandler to a FloatItem and looks for a tab. In Firefox this works fine. In Chrome the KeyPressHandler fires for the tab on the field prior to the FloatItem in the form. It doesn't fire when a tab is pressed while focused on the FloatItem itself.
Here is the code (it is attached as well):
Code:
package com.smartgwt.sample.client; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.core.KeyIdentifier; import com.smartgwt.client.util.EventHandler; import com.smartgwt.client.util.KeyCallback; import com.smartgwt.client.util.Page; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.FloatItem; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; import com.smartgwt.client.widgets.layout.VLayout; public class TabbingIssue implements EntryPoint { private DynamicForm form; public void onModuleLoad() { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new KeyCallback() { public void execute(String keyName) { SC.showConsole(); } }); VLayout example = new VLayout(); form = new DynamicForm(); form.setNumCols(4); TextItem text1 = new TextItem(); FloatItem float1 = makeFloatItem(); TextItem text2 = new TextItem(); FloatItem float2 = makeFloatItem(); form.setItems(text1, float1, text2, float2); example.addMember(form); example.draw(); } private FloatItem makeFloatItem() { FloatItem floatItem = new FloatItem(); floatItem.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { System.out.println("User hit key: " + event.getKeyName()); if (("Tab".equals(event.getKeyName()) == true) && (EventHandler.shiftKeyDown() == false)) { FormItem fields[] = form.getFields(); FormItem currentItem = event.getItem(); FormItem lastItem = fields[fields.length - 1]; if (currentItem.equals(lastItem)) { event.cancel(); addNewRow(); } } } }); return floatItem; } protected void addNewRow() { FormItem fields[] = form.getFields(); FormItem moreFields[] = new FormItem[fields.length + 2]; System.arraycopy(fields, 0, moreFields, 0, fields.length); moreFields[fields.length] = new TextItem(); moreFields[fields.length + 1] = makeFloatItem(); form.setFields(moreFields); form.redraw(); moreFields[fields.length].focusInItem(); } }
Version info:
SmartClient Version: v8.2p_2012-04-10/Enterprise Deployment (built 2012-04-10)
Google Chrome: 18.0.1025.168
Firefox: 11.0
Safari: 5.1
Comment