Hi Kevin,

conditional validation with "validwhen" should work in Jahia. There is 
only a bug for File field validations, which has been fixed in Jahia 5 
SP4, but that seems not to be your current problem, although we 
recommend you to consider switching to SP4 anyway ;-).

Your problem seems more to be the wrong usage of the validwhen 
condition. I believe that you would like to make the "docLink" mandatory 
only when "docODS" is set to 'Link', right?

With your condition:
<var-value>(docODS != 'Link')</var-value>

the docList entry will only be valid if the docODS is not 'Link', once 
it is 'Link' it will never be valid regardless of being empty or not empty.

You need also to include *this* into your condition and rather use a 
condition for docLink like this:

<var-value>((*this* != null) or (docODS != 'Link'))</var-value>

This means that validation of docLink will pass when docODS is not 
'Link', but if it is 'Link' it will only pass when the current value for 
'docLink' is set.

Hope this helps.

Regards,
Benjamin

On 27.06.2008 23:38 Kevin wrote:
> Hi,
> 
> We need some advice on validation in Jahia, specifically conditional
> validation of a Jahia container.
> 
> Validation seems to be done with Struts Validation rules. OK. I've
> done that in systems of my own in the past.
> 
> We've been able to make validation work for simple rules in Jahia such
> as "is a field required or not"
> However, if we want to make a field required conditionally, we've run
> into some strange problems.
> 
> It seems that if you use the "validwhen" argument, it works the first
> time in that Jahia stops you and displays your validation message
> (such as "x is required when y is foo").
> 
> But, if you put in the valid text and click OK it should pass
> validation, create the record and close the Content Object window.
> Instead, it reloads the pages and continues to display the validation
> message.
> 
> Has anyone come across this? Has anyone tried to do conditional
> validation of fields in Jahia?
> 
> Also notice below that the expression we are trying to validate is :
> (docODS != 'Link')
> In theory, it should be this (in our mind):
> (docODS == 'Link')
> However, we had to reverse it to get the expected validation message.
> We don't know why.
> 
> Please help. This is very frustrating.
> 
> ===========================
> excerpted from our Struts validation XML file:
> ===========================
> <form name="docBean">
>     <field property="docName" depends="required">
>         <arg0 key="label.doc.name"/>  
>     </field>
>     <field property="docSymb" depends="required">
>         <arg0 key="label.doc.symb"/>  
>     </field>
>     <field property="docDate" depends="required">
>         <arg0 key="label.date"/>      
>     </field>
>     <field property="docLink" depends="validwhen">
>         <arg0 key="label.doc.link"/>  
>               <var>
>                       <var-name>test</var-name>
>                       <var-value>(docODS != 'Link')</var-value>
>               </var>
>     </field>
> </form>
> 
> ===========================
> Definition of our container (it's a child of box from corp v2 templates)
> ===========================
> <content:declareContainerList
>     name='<%="docs" + id%>' title="Documents"
>     titleKey="boxContainer.docsContainer" bundleKey="<%=resBundleID%>"
>     aliasNames="boxDocs" validatorKey="docBean"
>               containerBeanName="jahiatemplates.org.foo.pojo.DocBean"
>     <content:declareContainer>
>         <content:declareField name="docName"
>             title="Document Name" type="SmallText"
>             titleKey="boxContainer.docs.name" bundleKey="<%=resBundleID%>"
>             aliasNames="boxDoc"
>         />
>         <content:declareField name="docSymb"
>             title="Document Symbol" type="SmallText"
>             titleKey="boxContainer.docs.symb" bundleKey="<%=resBundleID%>"
>             aliasNames="boxDocSymb"
>         />
>         <content:declareField name="docDesc"
>             title="Description" type="SmallText"
>             titleKey="boxContainer.docs.desc" bundleKey="<%=resBundleID%>"
>             aliasNames="boxDocDesc"
>         />
>         <content:declareField name="docDate"
>             title="Date Issued" type="Date"
>             titleKey="boxContainer.docs.date" bundleKey="<%=resBundleID%>"
>             aliasNames="boxDocDate"
>         />
>                       <content:declareField name="docODS"
>             title="Link Type" type="SmallText"
>             value="<jahia_multivalue[ODS:File:Link]>ODS"
>             titleKey="boxContainer.docs.ODS" bundleKey="<%=resBundleID%>"
>             aliasNames="boxDocODS"
>         />
>         <content:declareField name='docLink'
>             title="Document Link" type="SmallText"
>             titleKey="boxContainer.docs.link" bundleKey="<%=resBundleID%>"
>             value="<linkonly,external>"
>             aliasNames="boxDocLink"
>         />
>         <content:declareField name="docFile"
>             title="Document File" type="File"
>             titleKey="boxContainer.docs.file" bundleKey="<%=resBundleID%>"
>             aliasNames="boxDocFile"
>         />
>     </content:declareContainer>
> </content:declareContainerList>
> 
> ===========================
> 
> Thanks for any information you can provide.
> 
> Kevin
> _______________________________________________
> template_list mailing list
> [email protected]
> http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list
> 
_______________________________________________
template_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/template_list

Reply via email to