It appears that some FormItem types do not trigger the parent Form's ItemChangedHandler when default values are set?
Issue demonstrated here, though not exhaustively.
SmartClient Version: v9.1p_2016-07-08/PowerEdition Deployment (built 2016-07-08)
Chrome 51.0.2704.106 m
Issue demonstrated here, though not exhaustively.
Code:
package com.smartgwt.sample.client; import java.util.Date; import java.util.Map; import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.events.ItemChangedEvent; import com.smartgwt.client.widgets.form.events.ItemChangedHandler; import com.smartgwt.client.widgets.form.fields.DateTimeItem; import com.smartgwt.client.widgets.form.fields.DoubleItem; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.TextAreaItem; public class DemoFormItemChangedSomeNot implements EntryPoint { @Override public void onModuleLoad() { final DynamicForm dynamicForm = new DynamicForm() { { setShowEdges(Boolean.TRUE); // setShowShadow(Boolean.TRUE); setAlign(Alignment.CENTER); setNumCols(4); setCellBorder(1); } }; dynamicForm.setFields(makeFormItems()); dynamicForm.addItemChangedHandler(new ItemChangedHandler() { @Override public void onItemChanged(ItemChangedEvent event) { Map<String, String> oldValues = dynamicForm.getOldValues(); String fieldName = event.getItem().getName(); String oldValue = oldValues.get(fieldName); String newValue = event.getNewValue().toString(); String msg = "Item Changed: " + event.getItem().getName(); msg += "<br />"; msg += "Old Value: " + oldValue; msg += "<br />"; msg += "New Value: " + newValue; SC.say(msg); } }); dynamicForm.draw(); } private FormItem[] makeFormItems() { FormItem[] formItems = new FormItem[] { makeSelectItem1(), makeTextAreaItem1(), makeDateTimeItem1(), makeDoubleItem() }; return formItems; } private FormItem makeDoubleItem() { DoubleItem doubleItem1 = new DoubleItem("doubleItem1", "DoubleItem #1") { { // Comment this line, and Form ItemChangedHandler works. setDefaultValue(0.1D); } }; return doubleItem1; } private FormItem makeDateTimeItem1() { DateTimeItem dateTimeItem1 = new DateTimeItem("dateTimeItem1", "DateTime #1") { { // Comment this line, and Form ItemChangedHandler works. setDefaultValue(new Date()); } }; return dateTimeItem1; } private FormItem makeTextAreaItem1() { TextAreaItem textAreaItem1 = new TextAreaItem("textAreaItem1", "Text Area #1") { { setWrapTitle(Boolean.FALSE); // No problem here setDefaultValue("Not all FormItem types trigger Form ItemChanged handler, when default values are set?"); } }; return textAreaItem1; } private FormItem makeSelectItem1() { SelectItem selectItem = new SelectItem("selectItem1", "Select Item #1") { { setWrapTitle(Boolean.FALSE); setValueMap("Red", "Green", "Blue"); setDefaultToFirstOption(Boolean.TRUE); // No problem here. } }; return selectItem; } }
Chrome 51.0.2704.106 m
Comment