cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Messing, Elad" <>
Subject AW: Re: CFORMS - Performing a Form level validation
Date Wed, 01 Jun 2005 15:47:41 GMT
Hello again all !
	With the help of Sylvain and Thorsten I have managed to come up with the form.
	Now - when all data is valid, all works fine.
	The problem starts when the data is not valid.

	I have 3 widgets in my form - text field and a select list. (See definition below)
	On the text field there is a validation of length, and on the select list there is no validation,
but the first "item" of it is a null record - to show an empty slot.
	On the "form" there is a validation so that either of the 2 fields must contain value. (See
definition below)

	When I first show the form all is fine.

	When I enter a too-short string in the text field, I get a strange behavior: I can see the
error message stating it is too short, but I can also see the error message stating that either
of the fields should be entered (coming from the "form level" validation function) - like
nothing was entered in the text field. I added a "print" line into the form validation, to
see that even though I have entered a value in the text field (it was too short - but it was
there) the widget value is actually null. (see the "print" in the flow below).

	Also - I would expect the validation to stop after it was failing on the "too-short" text
field widget validation. Why has it continued to the "Form level" validation at all ?

	Another strange behavior was, that after I submitted the form with valid data, I could see
the results. When I pressed "Back" button of the browser - I got back to the form page, with
all the error messages still showing. The fields are showing the valid data which I put in,
but the errors from the first trail are still there. Why is that ? 

	And the third issue - When I am not using the "Back" button, but instead using the original
"link" to the form page, I get other results - I can see the form in the state it was after
I entered a "too-short" string in the text field !! This is after I have already changed the
data to valid, submitted, got my results, and return to the form page using its link 1 minute
after.. I even get the results opening a new browser window, in a different process. Only
"restart" to the web server removes it.
	Is this the normal behavior ? Should I reset the form in some manner ?

	I am attaching down the needed text from the flow and form description - maybe it can help
you understand my problems.

	Thank you very much for reading my long post :)



	<fd:messages id="errors">
		<fd:datatype base="string"/>
    <fd:field id="name">
      <fd:hint>Hint Hint</fd:hint>
      <fd:datatype base="string"/>
        <fd:length min="2">
	        <fd:failmessage>You should add name</fd:failmessage>

    <fd:field id="type">
      <fd:datatype base="integer"/>
      <fd:selection-list type="flow-jxpath" list-path="restTypeList" value-path="id" label-path="name"/>


function validateRestaurantForm (form){
	print ("Start validateRestaurantForm");
	var success = true;
	var nameWidget = form.lookupWidget("name");
	var typeWidget = form.lookupWidget("type");
	var errorsWidget = form.lookupWidget("errors");

  	print ("Name: " + nameWidget.value + " Type: " + typeWidget.value);
  	if (typeWidget.value == null && nameWidget.value == null ) {
		errorsWidget.addMessage("You must either select a name or type");
		print ("set the errors and return false");
      	success = false;
	return success;


-----Urspr√ľngliche Nachricht-----
Von: Sylvain Wallez [] 
Gesendet: Dienstag, 31. Mai 2005 21:08
Betreff: Re: CFORMS - Performing a Form level validation

Messing, Elad wrote:

> Hi all
>         I tried looking for a "definition" text on the preferred way 
> of performing a Form level validation.
>         What I mean is that I need to perform validation that is 
> relevant to the Form -not to specific widget. I.E. - I have a form 
> with 2 widgets, and I need to check that either 1 of them has a value 
> in it.
>         So - I know I can have a validation in one of the widgets, and 
> in it write some javascript to check the other as well, and then 
> output the error to a "fi:validation-errors" tag - to show it in a 
> central place.
>         But this seems like a work around rather than a real plan..

You can add a <fd:validation> on any widget, including a form. But not every widget
can hold validation errors, as not every widget has a visual representation.

So validation on non-visual widgets should set validation errors on one of their child widgets.
Another option if there's no suitable widget to attach the error to is to add the error text
to a <fd:message> widget.

For more details, see the javadocs of
o.a.c.forms.validation.WidgetValidator and form1.xml in the samples: the "contacts" repeater
has a validator that checks row uniqueness and sets an error on the duplicate rows.

>         A second and related question will be - In my form with 2 
> widgets, each one of them has its own validation. So - they are not 
> required, but in case the user enters something into them, It should 
> be validated. After this validation, I will need to have the "Form 
> Level" validation I mentioned above.

That should occur automatically.

Hope this helps,

Sylvain Wallez                        Anyware Technologies  
Apache Software Foundation Member     Research & Technology Director

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message