On Apr 21, 2008, at 4/212:15 PM , Kevin C. Dorff wrote:

Sorry if these have been covered, I am somewhat new to T5, using 5.0.11.

First, onValidate seems to be called once for each form variable, BEFORE the setter is called for that form variable. While I understand that logic, it SEEMS makes things a touch difficult to check the value I want to validate, especially if I want to validate several variables at once, such as if I want to validate two password variables to make sure they are equal, or to
verify a login page. I can do something like

  onValidateFromPassword(String newPassword)

and the assume username was already validated and "set" and then try
"newPassword" for the user. This just seems awkward. Is it really
intentional that onValidate is called once per form variable and before each setter? I would prefer that all setters are called, the onValidate is called
so I can check stuff. Really not sure how this is best to be coded.


Sounds like what you really want is to just do:

onValidateFromForm() {
  ...
}

That will be called after all of the other setters, and all of the other validation constraints have been applied, and is the best place for doing things like:

  if(!equal(_password,_newpassword)) {
    ...
  }

(where equal is some null-safe equals method).


SECOND: if I want a form reset as a submit button to reset the state of the
form (all my fields are @Persist), if I have validation on the fields,
pressing "Reset" will trigger Javascript validation and not allow the
submit. I looked at the Component Reference on submit and don't see a way to short-circuit validation so I can perform the reset, and start nice and
fresh.

Well...
There's probably a "right" way to do this (but it's been a long while since I've dealt with a similar problem, and there wasn't a way back then).
So the way I kludged around this, was to do something like:

<input t:type="submit" value="Reset" onclick="this.form.onsubmit=null;"/>

The trick is that onsubmit is the function that calls all of the javascript validation. So you can clear all of that out by setting it to null, and the form will still submit fine. I haven't used this for a "reset" button, but I've used it for cancel buttons, where I need to cancel the form and return to some other page, but I also need to clear out saved state, etc.

Robert


--
View this message in context: 
http://www.nabble.com/T5%3A-question-about-onValidate-and-form-reset-tp16809659p16809659.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to