I’ve found another example of different behavior of a dynamic form in the calendar editor. I’ve set this code in a popup window:
public DynamicForm getTestForm(String user) {
DynamicForm form = new DynamicForm();
form.setDataSource(MedicationsDataSource.getInstance(user));
final DateItem treatStart = new DateItem(MedicationsDataSource.START_TREATMENT, "From");
treatStart.setUseTextField(true);
treatStart.setShowPickerIcon(true);
final TimeItem time = new TimeItem(MedicationsDataSource.START_TREATMENT_TIME, "At");
time.setShowTitle(true);
final DateItem treatEnd = new DateItem(MedicationsDataSource.END_TREATMENT, "To");
treatEnd.setUseTextField(true);
treatEnd.setShowPickerIcon(true);
IntegerItem doseItem = new IntegerItem();
doseItem.setName(MedicationsDataSource.DOSE);
doseItem.setTitle("Dose");
ComboBoxItem unitsItem = new ComboBoxItem();
unitsItem.setName(MedicationsDataSource.UNITS);
LinkedHashMap<String, String> unitValues = new LinkedHashMap<String, String>();
unitValues.put("tablet", "Tablet");
unitValues.put("sachet", "Sachet");
unitsItem.setValueMap(unitValues);
unitsItem.setShowTitle(false);
final FloatItem freqItem = new FloatItem();
freqItem.setName(MedicationsDataSource.FREQUENCY);
freqItem.setTitle("Every");
ComboBoxItem periodItem = new ComboBoxItem(MedicationsDataSource.PERIOD);
LinkedHashMap<String, String> periodValues = new LinkedHashMap<String, String>();
for (PeriodType period : PeriodType.values()) {
periodValues.put(period.toString(), period.toString().toLowerCase());
}
periodItem.setValueMap(periodValues);
periodItem.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent event) {
String strValue = (String) event.getValue();
//Window.alert("Selected "+strValue);
boolean enable = true;
if (PeriodType.ONCE.toString().equals(strValue)) {
enable = false;
treatStart.hide();
time.hide();
treatEnd.hide();
freqItem.disable();
} else {
treatStart.show();
time.show();
treatEnd.show();
freqItem.enable();
}
}
});
periodItem.setShowTitle(false);
periodItem.setColSpan(2);
form.setItems(doseItem,unitsItem,freqItem,periodItem, treatStart,time,treatEnd);
return form;
}
...............
final com.smartgwt.client.widgets.Window popup = new com.smartgwt.client.widgets.Window();
popup.setAutoCenter(true);
popup.setAutoSize(true);
popup.addItem(getTestForm(user));
Button popupButton = new Button("Popup");
popupButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
popup.show();
}
});
When I click on the button, I get a window with the form. In the periodItem combo, if I select once, the handler executes correctly and the rest of the fields are hidden/disabled. However the same fields in a Calendar editor form:
Calendar cal = new Calendar();
..............
exactly the same fields description
..............
cal.setEventEditorFields(descItem,doseItem,unitsItem,freqItem,periodItem, treatStart,time,treatEnd);
When I select a value from the periodItem combo I get the following error:
16:41:22.401:INFO:Log:isc.Page is loaded16:46:12.994:WARN:Log:TypeError: com_smartgwt_client_widgets_form_fields_FormItem_$hide__Lcom_smartgwt_client_widgets_form_fields_FormItem_2_self_0.hide is not a function
I get the same error in the disable function, if I put it first.