I have the following code which lays 3 items in 2 columns and 2 rwos. First two items are in first row while 3rd TextAreaItem is in last row is expected to span both columns.
What I am finding is that the TextArea is only as wide as 1 column instead of 2.
DynamicForm form = new DynamicForm();
form.setNumCols(2);
TextItem nameItem = new TextItem();
nameItem.setTitle("Name");
nameItem.setRequired(true);
nameItem.setTitleOrientation(TitleOrientation.TOP);
TextItem parentItem = new TextItem();
parentItem.setTitle("Parent Organization");
//parentItem.disable();
parentItemItem.setTitleOrientation(TitleOrientation.TOP);
TextAreaItem descriptionItem = new TextAreaItem();
descriptionItem.setTitle("Description");
descriptionItem.setTitleOrientation(TitleOrientation.TOP);
descriptionItem.setWrap(TextAreaWrap.SOFT);
descriptionItem.setColSpan(2);
form.setFields(new FormItem[]{nameItem, parentItem, descriptionItem});
Also note that if I uncomment the line with parentItem.disable() then I get the following error in GWT Console. Why is that?
com.google.gwt.core.client.JavaScriptException: (TypeError): self.disable is not a function
fileName: jar:file:/home/najmi/.m2/repository/com/smartgwt/smartgwt/1.0b2-SNAPSHOT/smartgwt-1.0b2-SNAPSHOT.jar!/com/smartgwt/client/widgets/form/fields/FormItem.java
lineNumber: 1656
stack: ()@jar:file:/home/najmi/.m2/repository/com/smartgwt/smartgwt/1.0b2-SNAPSHOT
Regarding the disable() call, this method should be called to disable a control at runtime. Use FormItem.setDisabled(true) when setting up the control.
If you take a look at the example screenshot here you see that labels for first 2 textItems are above and not to the left of the field. So they do not actually use an extra column. Also nothing changes if my code was modified as follows (changed to 4 columns):
DynamicForm form = new DynamicForm();
form.setNumCols(4);
TextItem nameItem = new TextItem();
nameItem.setTitle("Name");
nameItem.setRequired(true);
nameItem.setTitleOrientation(TitleOrientation.TOP);
TextItem parentItem = new TextItem();
parentItem.setTitle("Parent Organization");
//parentItem.disable();
parentItemItem.setTitleOrientation(TitleOrientation.TOP);
TextAreaItem descriptionItem = new TextAreaItem();
descriptionItem.setTitle("Description");
descriptionItem.setTitleOrientation(TitleOrientation.TOP);
descriptionItem.setWrap(TextAreaWrap.SOFT);
descriptionItem.setColSpan(4);
form.setFields(new FormItem[]{nameItem, parentItem, descriptionItem});
Lastly any idea what is the issue with parentItem.disable() line? How can I make the text field inactive for a TextItem?
TextAreaItem has a fixed default width. setWidth(*) to fill the columns. Be sure also that your colWidths make sense, note that the default is to size every other column to the default titleWidth on the assumption that labels will appear in those columns.
Try as I may, I could not understand your suggestion above. I am sorry to ask if you could be more explicit and assume I am a complete newbie to SmartGWT/SmartClient/JavaScript/GWT (I am trying to get better).
BTW, I have a similat issue with DynamicForm.setNumCols not working as expected in code below. The resulting UI does not lay out ButtonItems in 3 columns as expected.
public class PublishCanvas extends Canvas {
public PublishCanvas() {
this.setWidth100();
DynamicForm form = new DynamicForm();
form.setHeight100();
form.setWidth100();
form.setNumCols(6);
ButtonItem orgItem = new ButtonItem("Organization");
orgItem.setIcon("PublishSensors.png");
ButtonItem serviceInterfaceItem = new ButtonItem("Service Interface");
serviceInterfaceItem.setIcon("PublishServiceInterfaces.png");
ButtonItem personItem = new ButtonItem("Person");
personItem.setIcon("PublishSensors.png");
ButtonItem serviceBindingItem = new ButtonItem("Service Binding");
serviceBindingItem.setIcon("PublishServiceInterfaces.png");
ButtonItem docItem = new ButtonItem("Document");
docItem.setIcon("PublishSensors.png");
ButtonItem serviceInstanceItem = new ButtonItem("Service Instance");
serviceInstanceItem.setIcon("PublishServiceInterfaces.png");
ButtonItem datasetItem = new ButtonItem("Data Set");
datasetItem.setIcon("PublishDatasets.png");
form.setFields(new FormItem[]{orgItem, serviceInterfaceItem, personItem, serviceBindingItem, docItem, serviceInstanceItem, datasetItem});
this.addChild(form);
}
I have not solved this issue and believe there may be a bug in SmartGWT or SmartClient manifested when the field label is above the active field rather than to its left as is the case in my test scenario.
I have uploaded a minimal test project which uses gwt-maven-plugin here.
You’ve got no calls to setStartRow(false) or setEndRow(false), so no, definitely not a bug. You were already given an (indirect) link to the Form Layout overview, please make sure to read it closely.
Again, try as I may I have had no luck with using setStartRowand setEndRow.
It is not for lack of trying or lack of RTFM.
Here is my complete and minimal code. I would be grateful if you could tell me exactly what I need to do to get the descriptionItem to take up 3 columns of the form for its active text field and 1 column for its label.
BTW as you can see the problem has nothing to do with titleOrientation as I had originally suspected.
package com.test.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.core.KeyIdentifier;
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.FormItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.layout.VLayout;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Application implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
//Following is to launch the dev console on Ctrl-D
KeyIdentifier debugKey = new KeyIdentifier();
debugKey.setCtrlKey(true);
debugKey.setKeyName("D");
Page.registerKey(debugKey, new KeyCallback() {
public void execute(String keyName) {
SC.showConsole();
}
});
Cookies.setCookie("skin", "SilverWave");
final String initToken = History.getToken();
VLayout vLayout = new VLayout(5);
vLayout.setWidth100();
DynamicForm form = new DynamicForm();
form.setNumCols(4);
TextItem nameItem = new TextItem();
nameItem.setTitle("Name");
TextItem parentItem = new TextItem();
parentItem.setTitle("Parent Name");
parentItem.setEndRow(true);
TextItem descriptionItem = new TextItem();
descriptionItem.setTitle("Description");
descriptionItem.setStartRow(true);
descriptionItem.setEndRow(true);
descriptionItem.setColSpan(3);
form.setFields(new FormItem[]{nameItem, parentItem, descriptionItem});
vLayout.addMember(form);
RootPanel.get().add(vLayout);
}
}