Setting validation limited per site

Hi,

I’m trying to set up validation on our image content type, so that we can set a maximum width for thumbnails. I’ve got this to work with a limit hardcoded into the validation of the field for the thumbnail width (which is populated automatically using the sys_imageInforExtractor() extension as an item pre-processor) as per the attached screenshot.

What I’d really like to do is allow the limit to be different for each of our sites. But that does not appear to be possible using the same method, because attempting to replace 91 with a variable name (setting aside how such a variable would be setup: site variables in the Publishing tab?) causes a Rule Validation Error saying the “number value should be numeric.”

Before I abandon this, and tell our internal customers that they’ll have to agree a maximum thumbnail width between them, or lump it, is there an alternative approach?

Thanks,

Andrew.

I haven’t tried this, so it’s pure speculation. But what if instead of using a Number Range validation, you used a Conditional validation? Basically, set it up yourself to confirm that the image_width is greater than minimum_value and less than maximum_value, instead of using the Number Range to do that? I think the Conditional validation can use variables.

Thanks for the suggestion. The same thing occurred to me as soon as I posted this thread. But I have been struggling with it ever since because, for some reason, I get java.lang.RuntimeException: contentid may not be null errors when trying to create an item, whenever I have included a condition along the lines of:

PXSContentItemData/img2_width < 91

You said you’re getting the error when you try to create the item… is it possible the conditional doesn’t like the img2_width being empty/null (which presumably it would be on creating a new item, since it’s set later through the infoExtractor)? What if you put a prereq on the validation that checks to make sure img2_width is not empty/null, so that the range validation only occurs when that field is actually set to something?

Still speculation, but it sounds logical.

Andrew,

There are 2 separate issues here, so I’ll respond to them separately…

Regarding the validation error when you create an item, this is caused by the fact that you are using Content Item Data.

Paul Howard explains this here:

http://forum.percussion.com/showpost.php?p=3452&postcount=3

You cannot do this in a field validation, because there is no data when the item is being created.

The underlying problem with this is the content items are not “site centric”. A given item may appear on many sites, and there is no easy way to associate the item with a site in the content editor.

Of course, we do know about site id when assemblying / previewing an item, but the validation happens in the “editor” portion of the system, which doesn’t understand sites.

As for your specific question, the only “variables” you can pass to a field validation are HTML Parameters, which must be in the content editor form. I recall a recent discussion here about this subject, but I cannot find a specific thread reference.

Dave

Thanks for those pointers.

I have added a reply to the Paul Howard thread you referenced, because although he explained it, he didn’t give a solution to the original poster’s (and now my) query - how do you reference the field’s value in a Conditional validation type rule?

As for the other issue, we have used the user’s current community, accessed via the User Context variable User/SessionObject/sys_community, to hide and reveal some fields based on the user’s community ID. I assume if I had a way to reference the field’s value in a Conditional validation type rule, I could set up several Conditional validation type rules, each setting the allowed width of the thumbnail for each community. This wouldn’t work for everyone, but our sites and communities do map on to each other.

Thanks,

Andrew.

Thanks to more info from Paul Howard I’ve managed to get this working with Conditional type validation as shown in the attached screenshot. This is a field validation of the img2_width field, referencing the value of the field via the “Single HTML Parameter” type in the Value Selector dialog. You have to type in the name of the field, because it is not shown in the list of Choices in that dialog.

Unlike using JEXL validation, the value is an integer if the field (img2_width in this case) uses the integer datatype. Hence I could have used greater-than, less-than, etc.

It is not an example of different validation per site, but it is an example of different validation per community, which is good enough for our use. YMMV.

Andrew.