You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Adam Walsh <aw...@contal.net.au> on 2004/07/15 05:30:24 UTC

CForms javascript validation

Hi,

I have a form with two fields in it, where at least one of the fields 
must be filled in, and I've put a bit of javascript to check it in the 
form definition:

<fd:field id="field1" required="false">
        <fd:label>field 1</fd:label>
        <fd:datatype base="string"/>
        <fd:validation>
            <fd:javascript>
                    if (widget.getValue() == null &amp;&amp; 
widget.getParent().lookupWidget("field2").getValue() == null)
                    {
                            var i18nMessage = new 
Packages.org.apache.cocoon.forms.util.I18nMessage("someErrorMsg", "tt");
                            widget.setValidationError(new 
Packages.org.apache.cocoon.forms.validation.ValidationError(i18nMessage));
                            return false;
                    }
                   
                    return true;
            </fd:javascript>
        </fd:validation>
    </fd:field>
    <fd:field id="field2" required="false">
        <fd:label>field 2</fd:label>
        <fd:datatype base="string"/>
    </fd:field>


This seems to work ok, except that if it fails once it doesn't seem to 
recognise new values for field2 when the form is submitted again. It 
seems to always think that field2 is empty even when it's not. Is this a 
bug, or am I doing something stupid? Is there a better way I should be 
doing this validation?

Thanks,
Adam

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


Re: CForms javascript validation

Posted by Adam Walsh <aw...@contal.net.au>.
Ah, that makes sense :)

Thanks Joerg, that was exactly what I needed.

Adam


Joerg Heinicke wrote:

> On 15.07.2004 05:30, Adam Walsh wrote:
>
>> Hi,
>>
>> I have a form with two fields in it, where at least one of the fields 
>> must be filled in, and I've put a bit of javascript to check it in 
>> the form definition:
>>
>> <fd:field id="field1" required="false">
>>        <fd:label>field 1</fd:label>
>>        <fd:datatype base="string"/>
>>        <fd:validation>
>>            <fd:javascript>
>>                    if (widget.getValue() == null &amp;&amp; 
>> widget.getParent().lookupWidget("field2").getValue() == null)
>>                    {
>>                            var i18nMessage = new 
>> Packages.org.apache.cocoon.forms.util.I18nMessage("someErrorMsg", "tt");
>>                            widget.setValidationError(new 
>> Packages.org.apache.cocoon.forms.validation.ValidationError(i18nMessage)); 
>>
>>                            return false;
>>                    }
>
>
> What about:
>                      else {
>                            widget.setValidationError(null);
> >                          return true;
>                      }
>
>>            </fd:javascript>
>>        </fd:validation>
>>    </fd:field>
>>    <fd:field id="field2" required="false">
>>        <fd:label>field 2</fd:label>
>>        <fd:datatype base="string"/>
>>    </fd:field>
>>
>>
>> This seems to work ok, except that if it fails once it doesn't seem 
>> to recognise new values for field2 when the form is submitted again. 
>> It seems to always think that field2 is empty even when it's not. Is 
>> this a bug, or am I doing something stupid? Is there a better way I 
>> should be doing this validation?
>
>
> Joerg
>
> ---------------------------------------------------------------------
> 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


Re: CForms javascript validation

Posted by Joerg Heinicke <jo...@gmx.de>.
On 15.07.2004 05:30, Adam Walsh wrote:
> Hi,
> 
> I have a form with two fields in it, where at least one of the fields 
> must be filled in, and I've put a bit of javascript to check it in the 
> form definition:
> 
> <fd:field id="field1" required="false">
>        <fd:label>field 1</fd:label>
>        <fd:datatype base="string"/>
>        <fd:validation>
>            <fd:javascript>
>                    if (widget.getValue() == null &amp;&amp; 
> widget.getParent().lookupWidget("field2").getValue() == null)
>                    {
>                            var i18nMessage = new 
> Packages.org.apache.cocoon.forms.util.I18nMessage("someErrorMsg", "tt");
>                            widget.setValidationError(new 
> Packages.org.apache.cocoon.forms.validation.ValidationError(i18nMessage));
>                            return false;
>                    }

What about:
                      else {
                            widget.setValidationError(null);
 >                          return true;
                      }

>            </fd:javascript>
>        </fd:validation>
>    </fd:field>
>    <fd:field id="field2" required="false">
>        <fd:label>field 2</fd:label>
>        <fd:datatype base="string"/>
>    </fd:field>
> 
> 
> This seems to work ok, except that if it fails once it doesn't seem to 
> recognise new values for field2 when the form is submitted again. It 
> seems to always think that field2 is empty even when it's not. Is this a 
> bug, or am I doing something stupid? Is there a better way I should be 
> doing this validation?

Joerg

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