OK, I wrote a repeater validator in the form definition, here is what it looks like:

<fd:repeater id="promos">
<fd:validation>
<javascript>
print ("validating repeater");
var ok = true;
for (var i = 0; i &lt; widget.size; ++i) {
var row = widget.getRow(i);

// yuk...
var text = row.getWidget("text").value;
if (text == null) {
text = new String();
} else {
text = new String(new java.lang.String(text).trim());
}

if (row.getWidget("deleteMe").value == "true") { // see [2] below
row.getWidget("text").setValidationError (null);
} else if (text.length == 0) {
row.getWidget("text").setValidationError (
new Packages.org.apache.cocoon.forms.validation.ValidationError
("missing required promo text")
);
ok = false;
}
}
return ok;
</javascript>
</fd:validation>

The idea is that if the text widget is empty, we set a validation error (pseudo-required field), unless the deleteMe booleanfield is checked, in which case we will just delete the row without complaining.

Two things:

[1] The problem I'm having now occurs in this scenario:

1 - add a row, but don't fill in the text field or check the delete box;
2 - submit the form;
3 - form is redisplayed with a validation error;
4 - now check the delete box and resubmit.

In this scenario, my validation script above never fires! So the form is just redisplayed again with the validation error. Why is this? The only thing I can think of is that the field that has the validation error in step (3) above does not change in step (4), and that it might have something to do with that...?

[2] I have to use this expression to test the value of the checkbox in the validation script:

row.getWidget("deleteMe").value == "true"

Where did the conversion to string come from? That doesn't happen in flowscript — the type of a widget's 'value' property is a boolean in flowscript, why is it a string here? This really messed with my mind... :-/

~mark

Reply via email to