Is there an issue with CanvasItem and ValuesManager? It doesn't seem to be saving the value in values manager for my custom canvas item. It gets to the validator code fine but never gets to the getValue(), setValue() methods. Reading elsewhere in the forum, I added setShouldSaveValue(true), etc. what else am I missing.
Also added there seems to be an issue with the tab order with the outer form, this canvasitem is part of an outer form with other fields, but the tab order is always first for this canvasitem even if I set the tab order on the outer form fields. I also added this.setCanFocus(true) as per recommendations in other forum posts.
Here is the snippet of code for CanvasItem
I am using GWT 2.4 and one of the recent 3.0 LGPL nighly .
Also added there seems to be an issue with the tab order with the outer form, this canvasitem is part of an outer form with other fields, but the tab order is always first for this canvasitem even if I set the tab order on the outer form fields. I also added this.setCanFocus(true) as per recommendations in other forum posts.
Here is the snippet of code for CanvasItem
Code:
public class SplitPhoneItem extends CanvasItem { private DynamicForm phoneForm; boolean required; private TextItem phoneField1; private TextItem phoneField2; private TextItem phoneField3; public SplitPhoneItem(final String name, final String title) { this(name); super.setTitle(title); } public SplitPhoneItem(final String name) { super.setRequired(false); super.setShowErrorIcon(true); super.setName(name); setShouldSaveValue(true); this.setCanvas(asWidget()); this.setCanFocus(true); final Validator validator = new CustomValidator() { @Override protected boolean condition(final Object value) { phoneForm.clearErrors(true); final boolean validate = phoneForm.validate(); if (validate == false) { final Map errors = phoneForm.getErrors(); if (Utility.isNotNull(errors) && (errors.isEmpty() == false)) { // TODO: error message handling } } else { storeValue(value); } return validate; } }; validator.setErrorMessage("Invalid phone"); this.setValidators(validator); } private Canvas asWidget() { final HLayout layout = new HLayout(); layout.setHeight(20); phoneForm = new DynamicForm(); phoneForm.setNumCols(6); phoneForm.setShowErrorIcons(true); phoneForm.setHiliteRequiredFields(false); phoneField1 = new TextItem(); phoneField1.setValidators(customLengthValidator(3)); phoneField1.setWidth(60); phoneField1.setShowTitle(false); phoneField1.setRequired(this.required); phoneField1.setShowErrorIcon(false); phoneField1.setMask("###"); phoneField2 = new TextItem(); phoneField1.setValidators(customLengthValidator(3)); phoneField2.setWidth(60); phoneField2.setShowTitle(false); phoneField2.setRequired(this.required); phoneField2.setShowErrorIcon(false); phoneField2.setMask("###"); phoneField3 = new TextItem(); phoneField1.setValidators(customLengthValidator(4)); phoneField3.setWidth(80); phoneField3.setShowTitle(false); phoneField3.setRequired(this.required); phoneField3.setShowErrorIcon(false); phoneField3.setMask("####"); phoneForm.setFields(phoneField1, phoneField2, phoneField3); layout.addChild(phoneForm); return layout; } @Override public String getValue() { // return phoneForm.getValueAsString(getPhoneItemName(1)) + phoneForm.getValue(getPhoneItemName(2)) + phoneForm.getValue(getPhoneItemName(3)); return (String) super.getValue(); } public void showValue() { //todo ? } @Override public void setValue(final String value) { phoneForm.getField(getPhoneItemName(1)).setValue(value.substring(0, 2)); phoneForm.getField(getPhoneItemName(2)).setValue(value.substring(3, 5)); phoneForm.getField(getPhoneItemName(3)).setValue(value.substring(6, 9)); super.setValue(value); } @Override public void setTitle(final String title) { super.setTitle(title); } @Override public void setRequired(final Boolean required) { this.required = required; phoneField1.setRequired(required); phoneField2.setRequired(required); phoneField3.setRequired(required); } @Override public Boolean validate() { return phoneForm.validate(true); } @Override public void clearValue() { phoneForm.clearErrors(true); phoneForm.clearValues(); } }
Comment