Re: Form Validation with multi-lingual fields ?

[email protected]
Newsgroups gmane.comp.cms.jahia.devel
Message-ID <OF7E60A325.9654819F-ONC125708F.0032A582-C125708F.00402EA6@commaro.com>
The Jahia Field Input Validation Guide, which is currently linked on the 
Documentation page is unfortunately an older version. You should read the 
corrected text in Chapter 17 of the Jahia 4.x Template Developer Guide, 
which is also linked on the Documentation page.

On page 108 you can read the following:

>> The validator only accesses the getter-methods of those fields, for 
which you will define validation rules. The field values should be taken 
from the ContainerFacadeInterface object and for that you should use the 
inherited methods getJahiaField(String) or 
getJahiaMultiLanguageField(String). Which method to use depends on the 
validation rule, which should be applied. Most of the standard validators 
expect the field value as a String, but there are Jahia specific 
multilingual validations, which need to get access to all language entries 
of a field and for those fields you should return a JahiaMltHelper object.

If you want to apply both (standard validators and Jahia multilingual 
validators) to the same field you should provide two different 
getter-methods. In this special case, the getter method returning the 
String must match the field name property, while for the getter method 
returning the JahiaMltHelper you can choose any property name.<<

So if you use the standard "validwhen" validation rule, your bean method 
should return a String, even if the field-type is SMALLTEXT and the value 
is multilingual.

Just use:
     public String getImageAlt()
     {
         return getJahiaField("ImageAlt");
     }

This way your "validwhen" rule will check the value of ImageAlt for the 
current language somebody is working on. 

Greetings,
Benjamin

Sébastien Landeau <[email protected]> wrote on 30.09.2005 
17:05:38:

> Hello, 
> 
> 
> We have a container with 2 fields : 
> An Image Field (type FieldTypes.FILE)
> An ImageAlt Field (type FieldTypes.SMALLTEXT)
> 
> We want to check the following validation rule : "The  ImageAlt 
> field is mandatory only if the Image field is not null"
> 
> Code of the JavaBean associated to the ImageAlt field : 
> 
>     public JahiaMltHelper getImageAlt()
>     {
>         return getJahiaMultiLanguageField("ImageAlt");
>     }
> 
> 
> Here is an extract of the Jakarta validation Xml file : 
> < field property = "imageAlt" depends = "validwhen" >
>     < msg name = "validwhen" key = "errors.required" /> 
>     < arg0 key = "ImageAlt" resource = "false" /> 
>     < var > 
>         < var-name > test </ var-name > 
>         < var-value > ((image == null) or (*this* != null)) </ var-value 
> 
>     </ var > 
> </ field >
> This code doesn't work. 
> 
> 
> 
> 
> If the ImageAlt definition is changed to a FieldTypes.
> SMALLTEXT_SHARED_LANG type, the rule works fine with the
> following modification in the validation JavaBean :
>     public String getImageAlt()
>     {
>         return getJahiaField("ImageAlt");
>     }
> 
> In this special case all works fine. But we need multi lingual fields 
!!!
> 
> 
> Thank's for your help.
> 
> 
> Best regards...
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.