Hi John,
A somewhat more straightforward way is to use a parameter with the
special name "_eventName", which Stripes will use as the event name
if it finds a value for that parameter in the request.
Then you would have:
<input type="hidden" id="eventName" name="_eventName"/>
$("eventName").value='saveSelections';
As for not submitting the form if validation fails, not only must
you return false from your JavaScript (which you did), but also
return that value from the form, as in:
<form ... onsubmit="return false;">
...
<stripes:submit ... onclick="return validateSelections(this);"/>
For an explanation of the 'magic' that makes the original version work
with just a parameter name with the same name as the event handler,
please see Tim's answer here:
http://article.gmane.org/gmane.comp.java.stripes.user/8527
Hope that helps.
Cheers,
Freddy
http://www.stripesbook.com
- In reference to this thread:
- http://thread.gmane.org/gmane.comp.java.stripes.user/2141/focus=2191
-
- I was looking for a way to perform some client side validation before
- submitting my form. I noticed that if I use the submit button it submits
- even if validation fails.
- If I use a button tag then I have to create a hidden field similar to what
- Jasper did in order to set the eventName.
-
- Note I WANT to use JavaScript for client side validation and then decide
- whether or not to submit the form. This has nothing to do with image
- styling but is nevertheless related.
-
- Currently I am using the following code:
-
- function validateSelections(formObj) {
- if (isValidSelection(formObj)) {
- $("eventName").name='saveSelections';
- formObj.submit();
- }
- else {
- return false;
- }
- }
-
- Then in the form I have a hidden field:
- <input type="hidden" id="eventName"/>
-
- To be honest, I am not sure how this is working because I couldn’t find
- anything in the documentation on “eventName” and Jasper’s post used
- “stripesevent”. How does Stripes resolve this event from these hidden
- fields with seemingly arbitrary names?
-
- And more importantly, is there an easier way to do this in stripes?
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users