0

Forcing field validations

asked 2010-03-16 10:42:56 +0800

raevel2 gravatar image raevel2
72 1 2

I have a few form fields that i use constraints to validate. These fields depend on other fields in the form, so onChange is not the only time that i want validations to occur.

How do I force a validation to occur? I also want to make sure that no old validation errors remain on the page.

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-03-16 17:34:44 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-03-16 17:35:17 +0800

you can force a validation with getting the value for the field i.e.:
textbox.getValue();

best
Stephan

link publish delete flag offensive edit

answered 2010-03-17 05:34:42 +0800

raevel2 gravatar image raevel2
72 1 2

updated 2010-03-17 05:35:40 +0800

Are you sure?

I'm calling getValue on my textbox but the constraint is not being called, and the error message remains. If I focus and blur the field manually, the validation triggers again.

This is a wild guess: When I call getValue the validation will only trigger if the value has changed since the last validation.

Here's an example, if you click the fail button immediately on page load, the validation error will trigger (since a validation has not yet occured?). After that the only way to get the validation trigger is to blur the field:

<?page contentType="text/html;charset=UTF-8"?>
<zk>
  <zscript><![CDATA[
    import org.zkoss.zul.Constraint;
    import org.zkoss.zk.ui.WrongValueException;
    boolean fail = false;
    Constraint con = new Constraint() {
    	public void validate(Component comp, Object val) throws WrongValueException {
    	  if (fail) {
    	    throw new WrongValueException(comp, "fail");
    	  }
    	}
    }
  ]]></zscript>
  <window>
    <button id="button_fail" onClick="fail = true; textbox.getValue()" label="Fail"/>
    <button id="button_succeed" onClick="fail = false; textbox.getValue()" label="Succeed"/>
    <textbox id="textbox" constraint="${con}"/>
  </window>
</zk>

link publish delete flag offensive edit

answered 2010-03-17 06:48:24 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-03-17 06:49:56 +0800

Yes, i'm sure.

I have tested your code with 3.6.3 and 5.0.1. Seems in 5.0.1 it's more angry than in 3.6.3.
But you must focus the textbox after an error appears. The errormessage will show you which component must be corrected.
Yes, you are right that does not react correctly.

I think it's a problem of BSH. If you do it in a java controller without (zscript and bsh) it works fine.
Hope the ZK team can have a look on it.

best
Stephan

link publish delete flag offensive edit

answered 2010-03-21 23:10:06 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Hi Stephan,

I don't quite get what the issue is. Would you help post to ZK bugs that we can track it. Thanks.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-16 10:42:56 +0800

Seen: 442 times

Last updated: Mar 21 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More