Example code:
<window>
<zscript><![CDATA[
import org.zkoss.zul.*;
Constraint cons = new Constraint() {
public void validate(Component comp, Object value) throws WrongValueException {
throw new WrongValueException(comp, "You must upload an essence file");
}
};
void doValidation() {
cons.validate(button, null);
}
]]></zscript>
<button id="button" label="Button" onClick="doValidation();"/>
</window>
When the button is clicked, a validation error is triggered and a dialog is shown pointing towards the button (as expected).
Two problems occur here:
1. For every additional click on the button, a new error window pops up, meaning several will be stacked.
2. Only the dialog that was opened last is closable, the others remain indefinitely.
I expect only one dialog to be visible for one element at a time.
I'll add that in this particular example, clicking the dialog will spawn another dialog. I assume that this is because the onClick applies to the dialog as well and I can't tell whether it is expected behavior or not.
This is spec,
It will create a error box when you throws a exception every time
if you want "only one dialog to be visible for one element at a time"
you can post a feature request
OK,
Only the dialog that was opened last is closeable
Fixed since Mar 16 2010
This seems to be inconsistently implemented.
When i call validate on a textbox the validation only displays once, but when I do it on a button, serveral dialogs are displayed as I showed previously
Try the following example, clicking the left button will not spawn additional dialogs, while clicking the right one will.
<?page contentType="text/html;charset=UTF-8"?>
<zk>
<zscript><![CDATA[
import org.zkoss.zul.Constraint;
import org.zkoss.zk.ui.WrongValueException;
Constraint con = new Constraint() {
public void validate(Component comp, Object val) throws WrongValueException {
throw new WrongValueException(comp, "fail");
}
}
]]></zscript>
<window>
<button onClick="con.validate(textbox, null);" label="Fail on text field"/>
<button onClick="con.validate(button, null);" label="Fail on button"/>
<textbox id="textbox"/>
<button id="button" label="Button"/>
</window>
</zk>
Could you test with the latest ZK 5.0.1 version?
In my environment, the two buttons of "Fail on text field" and "Fail on button" did the same result for me.