Hello,

I have the following problem:

In XML I have an element "image" with two attributes @src and @alt.
If @src is filled in the CMS form, then @alt becomes a required field.

Looking at http://www.hippocms.org/display/CMS/Template+validation
I would say that this can be implemented with a bit of JavaScript
(flowscript). Section "More about javascript (flowscript) validation"
suggests there is a function lookupWidget( widget, xpath ) that
according to the description:

"Returns a widget object, relative to the widget passed as first
argument, using the relative/absolute xpath to that widget."

So I expected the following piece of code to work:

    <rule for="/document/content/paragraphs/paragraph/image">
      <validation>
      <validator name="javascript">
        <![CDATA[
          var srcWidget = lookupWidget(widget,"@src");
          var altWidget = lookupWidget(widget,"@alt");
          if ((srcWidget != null)){
            if (srcWidget.value != null && (widget.value == null ||
widget.value.length() <= 0)){
              setValidationError(widget,"Alt is required field.");
              return false;
            }
          }
          clearValidationError(widget); // clear previous validation errors
          return true;
        ]]>
      </validator>
      </validation>
    </rule>

It doesn't. Tried all sorts of variations: "./@xxx" paths, rule on @alt
with ../@src path, etc. In the end I tried something that doesn't use
lookupWidget at all:

    <rule for="/document/content/paragraphs/paragraph/image/@alt">
      <validation>
      <validator name="javascript">
        <![CDATA[
            if ((widget.value == null || widget.value.length() <= 0)){
              setValidationError(widget,"Alt is required field.");
              return false;
          }
          clearValidationError(widget); // clear previous validation errors
          return true;
        ]]>
      </validator>
      </validation>
    </rule>

This doesn't work either.

Can anyone explain what I am doing wrong or where I can find more
information to solve this?

Thanks,

Reinier

--

Reinier van den Born

HintTech B.V.
Rotterdamseweg 183c, 2629 HD Delft
T: +31(0)15 268 2573
F: +31(0)15 268 2567
M: +31(0)6 494 171 36
--
HintTech levert specialisten op het gebied van softwareontwikkeling
(.NET en Java),
projectmanagement, informatiebeveiliging en business consulting.
KvK Den Haag nr. 27242282 | BTW nr. NL8062.16.396.B01

begin:vcard
fn:Reinier van den Born
n:van den Born;Reinier
org:HintTech B.V.
adr:;;Rotterdamseweg 183c;Delft;;2629HD;Netherlands
email;internet:[EMAIL PROTECTED]
tel;work:+31-15-268 2573
tel;fax:+31-15-268 2567
tel;cell:+31-6 494 171 36
note;quoted-printable:KvK Den Haag nr. 27242282 | BTW nr. NL8062.16.396.B01=0D=0A=
	=0D=0A=
	HintTech levert specialisten op het gebied van softwareontwikkeling (.NET=
	en Java), projectmanagement, informatiebeveiliging en business consulting=
	.=0D=0A=
	=0D=0A=
	
url:www.hinttech.com
version:2.1
end:vcard

********************************************
Hippocms-dev: Hippo CMS development public mailinglist

Reply via email to