0

Clearing a form woth constraint="no empty" problem.

asked 2009-12-21 07:10:58 +0800

Fooch gravatar image Fooch
48 2

I have been trying to find an answer to this but have not had too much luck. Maybe I am not familiar enough with the terminology to search well, I am very new to ZK.

I have a form that has all the text and combo boxes have "no empty" constraints on them. The problem I am having, when I enter some information in these boxes and then try to clear them, whether it be because they entered a bunch of junk and want to start over, or they submitted the form and I want it cleared out in case they want to enter another record. But everytime I attempt to clear, the values stay in the boxes and I get error on the first text box saying that I need to have a value in it. "This field may not be empty or have just spaces in it".

Is there any way to clear the form without triggering that constraint?

Thanks in advance!

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-12-21 08:22:55 +0800

Rico gravatar image Rico
175 1 1 2

You can (at least for textbox/intbox and so on) use setRawValue("") or setRawValue(null) to avoid the constraint check (or You could disable the constraint while setting the values and the set the constarints again)

link publish delete flag offensive edit

answered 2009-12-21 08:53:09 +0800

Fooch gravatar image Fooch
48 2

Perfect! Thanks alot.

Also, you wouldn't happen to know how to setup custom constraints or how to get those error boxes to go away when your focus changes to another box?

link publish delete flag offensive edit

answered 2009-12-21 21:14:52 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

Check this:

http://www.zkoss.org/javadoc/3.6.1/zk/org/zkoss/zk/ui/util/Clients.html#closeErrorBox%28java.util.List%29

link publish delete flag offensive edit

answered 2009-12-22 01:10:28 +0800

Rico gravatar image Rico
175 1 1 2

It depends on what kind of custom constarints You want to set up? If You want to make Your own constraint classes, I have done a couple of these successfully - look into the Constraint interface.

Basically You implement the Constraint interface and implements the validate(Component c, Object value) method so that it throws a WrongValueException if the constraint is not fulfilled:


	public class MyConstraint implements Constraint
	{
		public void validate(Component arg0, Object arg1) throws WrongValueException
		{
			if (arg1 == null || !valid(arg1)) // valid is a method that returns false if argument fails the constraint
			{
				throw new WrongValueException(arg0, "Bummer!");
			}
		}

		private boolean valid(Object value)
		{
			// Do some checks and return true/false depending on the outcome - in this case just check if not null
			return (value != null);
		}
	}


Note that You have to use the given component when creating the WrongValueException to get the "standard" constraint error look, otherwise You'll get an alert-box with the error message

link publish delete flag offensive edit

answered 2010-03-27 21:41:43 +0800

dnal gravatar image dnal
27 1

friend help my pleasse

http://www.zkoss.org/forum/listComment/11824

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: 2009-12-21 07:10:58 +0800

Seen: 1,419 times

Last updated: Mar 27 '10

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