cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Leicester" <mark.leices...@efurbishment.com>
Subject Re: Cocoon Forms - validating required fields
Date Tue, 16 Nov 2004 17:58:48 GMT
Great, thanks!  So am I right in thinking that the answer to "Must I
resort to a custom Javascript handler?" is "yes".

A colleague and I were wondering why "required" is an attribute. If it was
an element instead, then it could contain a <fd:failmessage> too,
potentially avoiding the need for the extra javascript. Any comments?

Thanks for responding so rapidly to a question from someone who absented
himself from the Cocoon community for far too long, blundering about
instead with PHP. It's nice to be back.

Mark

> Mark,
> try this:
>
> <?xml version="1.0"?>
>
> <fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
> <fd:validation>
>    	<fd:javascript>
>    		var success = true;
>    		var password = widget.lookupWidget("password");
>    		if (password.value == null) {
>    			quantity.setValidationError(new
> Packages.org.apache.cocoon.forms.validation.ValidationError("Please
> enter password", false));
>    			success = false;
>    		}
>    		return success;
>    	</fd:javascript>
> </fd:validation>
>
> <fd:widgets>
>      <fd:field id="password" required="true">
>        <fd:label>Enter password:</fd:label>
>        <fd:datatype base="string"/>
>        <fd:validation>
>          <fd:range min="5" max="9">
>            <fd:failmessage>Please enter password.</fd:failmessage>
>          </fd:range>
>        </fd:validation>
>      </fd:field>
> </fd:widgets>
>
> </fd:form>
>
> regards
>
>
> Andrew
> On 16 Nov 2004, at 17:14, Mark Leicester wrote:
>
>> Hi all,
>>
>> When a user leaves a required field blank, is there a way to generate a
>> custom fd:failmessage for that specific field?
>>
>> For example: I have two required fields - username and password - both
>> required. Say the user enters their username, but leaves the password
>> field blank. I get the [general.field-required] message. How can I
>> override this with a custom message saying "Enter your password!
>> (please)". Must I resort to a custom Javascript handler?
>>
>> I've been out of active Cocoon development for nine months or so. It's
>> great to be back - and to see how far flow and forms have come on. Nice
>> work.
>>
>> Regards,
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message