By default, a formField spans one column. If I call setShowTitle(true), it spans 2 columns (one for the title, and other for the field).
I use: form.setErrorOrientation(FormErrorOrientation.RIGHT);
and form.setShowErrorText(true);
So, my field should span 3 columns: the first for the title, the second for the field, and the third for the errorText and his icon.
BUT, the errorText is on the same column as the field… The field change his size to show the errorText… I don’t want it…
How do I put errorText on the other column?
or… If there isn’t a way to put the errorText on the other column, is there a way to keep the field’s width, and increase the column’s width show the errorText widthout affect the field’s width?
Thanks in advance!
Interesting idea to put the errors in a separate column. However if you make the column very wide you should be able to avoid wrapping the error text if that’s your concern - have you tried that or is there some reason that’s not a solution?
Yes, I don’t want wrapping error, and I don’t want change field’s width to show error text.
But this is very difficult to do… If error text was in a different column, the field’s width wouldn’t change, and the error text wouldn’t wrapping. It would be perfect to me! Perhaps it’s generate a problem to the other peoples on form layout, because the error text doesn’t exist on the first time. It exists only when a validation failed… Unless we consider that error text will span a collumn even if he isn’t showed yet. So, the problem would be solved to everyone.
I’ve already tryed a lot of solutions to solve wrapping error and field’s width variation… It’s almost working the way I want. I need your help to solve the field’s width. Look what I’m doing now:
My form is:
form.setNumCols(2); //one for the title, and other for the field
form.setColWidths(1, "*");
I use setWrapTitle(false);
I know that 1 isn’t enough for the title, but I want the smallest width for this column, so, actually, there is a overflow and the width will be more than 1, but only the necessary to accomodate the title, that is what I want.
The second col is “*”, so, there is enough space to the field and error message widthout wrapping the error text.
The problem is:
-Specifying the width of the TextItem in pixels (textItem.setWidth(200)) : Even if the textField doesn’t occupy the whole column (there is space besides him to show the whole errorText) there is these problems:
Problem 1 - error text wrapping: The error text is wrapping.
Problem 2 - width field changes: the field will has his width decreased to show the errorText. The width of the textField before showing the errorText is the same as the sum of his new width plus the width of error text. The space available besides the textField isn’t used.
-
Specifying the width of the TextItem width “" (textItem.setWidth("”)) : Now the textField occupy the whole column (there is NOT space besides him to show the whole errorText). The same problems happens, of course.
Problem 1 - error text wrapping: the same problem
Problem 2 - width field changes: the same problem -
Specifying the width of the TextItem width TRASH (textItem.setWidth(“TrashFjakshfajsf”)) : The textField doesn’t occupy the whole column, because default width will be used, that is 150 (so, there is space besides him to show the whole errorText), the field will NOT has his width decreased to show the errorText. The error text will occuppy the space available besides the textField, that is what I want!!!
Problem 1 solved! It will avoid wrapping the error text
Problem 2 solved! The field will keep his width.
But there is a new problem: I defined trash on field’s width, so, the other problems were solved. But, I didn’t defined the width I want… He has the default width. If I specify the width I want, I will have the problemns 1 and 2 again. I don’t want width diferent of 150…
What can I do?
There’s now a setErrorMessageWidth() on FormItem that you could use to avoid your controls shrinking when messages are displayed. This should either already be in SVN or will be there shortly.
It’s in SVN.
Thanks, sjivan and Isomorphic!
I will try it now!
Thanks again and congratulations for your project.
Look…
If I use setErrorMessageWidth(0), the field’s width doesn’t change. It solve one of my problems!
But, the errorText continuous wrapping… Even if there is enough space to the whole errorText, the errorText continuous wrapping.
Am I doing something wrong?
Look… Wrapping the errorText isn’t the problem. Is normal wrapp text if there isn’t enough space to display the whole text. The problem is that he is wrapping even if there’s enough space.
But my errors text are short… creating a setWrapErrorText(boolean) solves my problem. I don’t know if it solves other people’s problems.
Could you give me some help?
Thanks in advance!!!
Hi thiro,
We wouldn’t expect wrapping in that case, especially since it wasn’t wrapping before when you provided a bad value for width. Make sure the column is as wide as you think it is; you can use the diagnostic category “formLayout” in the Developer Console to see how sizes are being computed.
Hi!
If I set an invalid value for width, errorText doesn’t wrapp and SmartGWT will use the default value (I’m not sure, but I think it’s 150). But errorText wrapp if I set a specific value, even if it is equals the default value.
Hi Thiro,
Any chance you can post a test case that shows this behavior?
Sure!
Call: new TestTextError().show();
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.FormErrorOrientation;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.validator.CustomValidator;
import com.smartgwt.client.widgets.form.validator.IsIntegerValidator;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.LayoutSpacer;
public class TestTextError extends Window{
private DynamicForm form;
private TextItem textItem1;
private TextItem textItem2;
private TextItem textItem3;
private TextItem textItem4;
private IButton saveButton;
private IButton cancelButton;
private IButton clearButton;
public TestTextError() {
createComponents();
doLayout();
defineValidators();
defineCallbacks();
}
private void createComponents() {
form = new DynamicForm();
form.setShowErrorText(true);
form.setErrorOrientation(FormErrorOrientation.RIGHT);
form.setRequiredTitleSuffix("*");
textItem1 = new TextItem("textItem1");
textItem1.setTitle("TextBox 1");
textItem1.setWrapTitle(false);
textItem1.setRequired(true);
textItem2 = new TextItem("textItem2");
textItem2.setTitle("Widthout Spaces");
textItem2.setWrapTitle(false);
textItem2.setRequired(true);
textItem3 = new TextItem("textItem3");
textItem3.setTitle("Not only spaces");
textItem3.setWrapTitle(false);
textItem3.setRequired(true);
textItem4 = new TextItem("textItem4");
textItem4.setTitle("Only integer");
textItem4.setWrapTitle(false);
textItem4.setRequired(true);
saveButton = new IButton("Salve");
cancelButton = new IButton("Cancel");
clearButton = new IButton("Clear");
}
private void doLayout() {
setTitle("Test ErrorText");
setAutoCenter(true);
setIsModal(true);
setCanDragResize(false);
setAutoSize(true);
setWidth(670);
setAutoHeight();
setShowResizer(true);
form.setWidth100();
form.setPadding(10);
form.setNumCols(2);
form.setColWidths(1, "*");
form.setCellBorder(1);
textItem1.setWidth(175);
textItem2.setWidth(175);
textItem3.setWidth(175);
textItem4.setWidth(175);
textItem1.setErrorMessageWidth(0);
textItem2.setErrorMessageWidth(0);
textItem3.setErrorMessageWidth(0);
textItem4.setErrorMessageWidth(0);
form.setFields(textItem1, textItem2, textItem3, textItem4);
HLayout buttonsLayout = new HLayout();
buttonsLayout.setWidth100();
buttonsLayout.setAutoHeight();
buttonsLayout.setDefaultLayoutAlign(Alignment.CENTER);
buttonsLayout.setMargin(10);
buttonsLayout.setMembersMargin(10);
buttonsLayout.addMember(new LayoutSpacer());
buttonsLayout.addMember(saveButton);
buttonsLayout.addMember(cancelButton);
buttonsLayout.addMember(clearButton);
buttonsLayout.addMember(new LayoutSpacer());
Label info = new Label("Look the space available beside the field. It's enought to not wrapp the errorText. Click Save to validate.");
info.setWidth100();
info.setAutoHeight();
info.setMargin(10);
addItem(form);
addItem(info);
addItem(buttonsLayout);
}
private void defineValidators() {
// textItem1.setValidateOnChange(true);
// textItem2.setValidateOnChange(true);
// textItem3.setValidateOnChange(true);
// textItem4.setValidateOnChange(true);
CustomValidator notOnlySpaceValidator = new CustomValidator() {
@Override
protected boolean condition(Object value) {
if(value==null) {
return true;
}
if(!(value instanceof String)) {
return false;
}
return ((String)value).trim().length()>0;
}
};
notOnlySpaceValidator.setErrorMessage("This field can't have only spaces.");
CustomValidator noSpaceValidator = new CustomValidator() {
@Override
protected boolean condition(Object value) {
if(value==null) {
return true;
}
if(!(value instanceof String)) {
return false;
}
return !((String)value).contains(" ") && !((String)value).contains("\t");
}
};
noSpaceValidator.setErrorMessage("This field can't have spaces.");
textItem2.setValidators(noSpaceValidator); textItem2.setValue("Text with spaces");
textItem3.setValidators(notOnlySpaceValidator); textItem3.setValue(" ");
textItem4.setValidators(new IsIntegerValidator()); textItem4.setValue("Not number text");
}
private void defineCallbacks() {
saveButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
if(form.validate()) {
SC.say("ok");
}
}
});
cancelButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
TestTextError.this.destroy(); //TODO is it the best option?
}});
clearButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
form.clearValues();
}});
}
}
Hopefully can give some workaround for you after following your forum for the same requirement that I need to implement. I tried by changing the css style of the errorMessage, don’t know you can apply this tru your smartgwt or not:
.formCellError {
white-space:nowrap;
}
Then I use your technique : errorMessageWidh:0, for the formItem.
Then the usual stuff on the Form : errorOrientation:“right”, showErrorText:true
I tested the workaround on FF3 and IE8 which looks ok for me.
I am using SmartClient 7.0RC directly instead of smartgwt.
I am looking for the same solution. By following this thread, I managed to get the following display. However, I will like to be able to center align the error text instead of top align. Does anyone know the way to align this?
Here is my code:
public class Textbox extends TextItem {
public Textbox(final String title) {
super();
super.setTitle(title);
this.setTitleAlign(Alignment.LEFT);
this.setWrapTitle(false);
this.setErrorOrientation(FormErrorOrientation.RIGHT);
this.setShowErrorText(true);
this.setShowErrorIcon(false);
this.setErrorMessageWidth(0);
}
}
.formCellError {
white-space:nowrap;
color:red;
vertical-align: middle;
}
![]()