Niall - some comments inline and other stuff below...

Niall Pemberton wrote:
I'm trying to get javascript validation working using the action mapping's
path as the validation key with Struts 1.2.4.

I don't usually use js (I'm trying to test something) but the generated
javascript doesn't appear to work - from where I'm sitting it looks broken -
can anyone confirm if they have it working or not?

I have the following mapping in my struts config:

<action path="/houseTypeAdd" type="....."
name="myForm" scope="request" validate="true" input="housetype.add">
     ...
</action>

And my jsp has the following form & javascript tags:

<html:form action="houseTypeAdd" focus="housetype_code"
      onsubmit="return validateHouseTypeAdd(this);">
     ...
</html:form>
<html:javascript formName="houseTypeAdd" bundle="niall-1"/>

There are three fields defined as 'required' and it genertes a javascript
function called houseTypeAdd_required () - however when I put an alert in
the required.js script it seems to be trying to call function named after
the form rather than the mapping (i.e. myForm_required()) - so its using the
form name rather than the mappings path.

I'm not sure what you are getting at here - from what I can tell from the code you posted, the form name and mapping name are the same, so either way it shouldn't make a difference (But see my comments below as well...)


Where do you expect myForm to come from (or not come from?)

What happens when the javascript validation kicks in? Javascript errors? Java errors? Nothing?


Can anyone see what I'm doing wrong or confirm it doesn't work? Below is relevant detail of the javascript being generated

Thanks

Niall

function validateHouseTypeAdd(form) {
   if (bCancel)
   return true;
   else
   var formValidationResult;
   formValidationResult = validateRequired(form);
   return (formValidationResult == 1);
}
function houseTypeAdd_required () {
   this.a0 = new Array("housetype_code", "[Bundle 1] custom {0} is
required.", new Function ("varName", " return this[varName];"));
   this.a1 = new Array("housetype_short_desc", "[Bundle 1] custom [Bundle 2]
short-desc-msg is required.", new Function ("varName", " return
this[varName];"));
   this.a2 = new Array("housetype_desc", "[Bundle 1] custom [Bundle 1]
description-msg is required.", new Function ("varName", " return
this[varName];"));
}
function validateRequired(form) {
   var isValid = true;
   var focusField = null;
   var i = 0;
   var fields = new Array();
   var formName = form.getAttributeNode("name");
   alert("validateRequired(form): about to call method: " + formName.value +
"_required()");
   oRequired = eval('new ' + formName.value + '_required()');
   for (x in oRequired) {


1.2.4 does indeed always use the form name instead of possibly using the action mapping name, check out bugzilla report:
http://issues.apache.org/bugzilla/show_bug.cgi?id=29796
for the bug and reasoning behind the patch.


I coded/tested the patch for that, and it worked fine for me then. I also use it on some test sites, and it was working fine for me the last time I used it there a week or so ago.

Is it possible we can see the generated html form tag, as well as the form bean definition and validator xml definition? I think it would help in solving this. Also, a description of exactly what you are seeing error wise (and even in your alert) would be helpful.



Matt



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



Reply via email to