-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I have a typical scenario:
<datebox id="datefrom" constraint="no empty" /> <datebox id="dateto" constraint="no empty" /> ... if (to.getValue().before(from.getValue()) { throw new WrongValuesException(new WrongValueException[] { /* error for datefrom */, /* error for dateto */ }); }
It displays two error boxes, that's really nice. But when the user changes just the value of "dateto", then it is still not possible to save the form, since the "datefrom" is still marked as wrong value (red border). Event if the user closes the error box shown for the "datefrom", then it still has the red border and the form is not possible to close. The user has to click into the "datefrom" datebox and then it is possible to save the form.
How to handle this situation? Is it possible to mark an input box as valid, when the user closes the error box?
So far, I am showing just an error Messagebox.
A workaround might be to close the error boxes in an onChange listener. But is also closes error boxes for "no empty" constraints.
Thanks
How to solve this problem
Another (complex) solution would be to implement your own constraint that handles both date fields.
@iantsai: Thanks, it might work. But it would be a little bit tedious to implement, since we have more such fields.
@madruga0315: How it can help? Do you mean I would have to call clearErrorMessage() for the other datebox in the complex Constraint implementation?
@madruga0315: Thanks, yeah, that's the proper solution, I have to call clearErrorMessage(true) for the other field in my own Constraint .
Hi guys, so event the clearErrorMessage(true) does not help me. Consider the following scenario:
1. datefrom value is "2010-06-06", dateto value is "2010-06-10"
2. the user sets the incorrect dateto as "2010-06-qq", the org.zkoss.zul.Datebox.coerceFromString(String) rises the WrongValueException and shows the user a message "You must specify a date ...". Now the value of dateto is still "2010-06-10", because the wrong string has not passed the coerceFromString() method.
3. the user changes datefrom to "2010-06-07", my validation calls dateto.clearErrorMessage(true), then a call dateto.getValue() returns "2010-06-10" and validation passes OK.
4. the user presses the OK button, my code just call datefrom.getValue(), dateto.getValue(), both passes OK, but the dateto returns "2010-06-10". So my code does not inform the user, that she has typed incorrect dateto, instead, it saves the old date to the database. The user is confused.
IMHO the validation is not designed well in the InputElement class. I think the raw value should be stored in some field "rawValue" and the constraint validation should be triggered each tome the getValue() is called.
This is a common problem. I have hoped ZK has some solution to it.
I have, hopefully, found a working workaround. I do not use own Constraint, but I make dependent validations when the user click Save button (<button label="Save" onClick=...). The code is like:
String errmsg = this.dateto.getErrorMessage(); if (errmsg != null && Obejcts.equals(errmsg, this.dateto.getAttribute("wrongValueStored")) { this.dateto.clearErrorMessage(true); } if (this.dateto.getValue().before(this.datefrom.getValue())) { errmsg = "cannot be before date from" this.dateto.setAttribute("wrongValueStored", errmsg); throw new WrongValueException(this.dateto, errmsg); }
Asked: 2010-04-30 03:01:34 +0800
Seen: 478 times
Last updated: Jun 11 '10