How to use JEXL for field Validation

Has anyone used JEXL for field validation. I want to be able to check if a field is set to a certain value. I would also like to be able to do some more complex validation, for example, if one field has a string length > 0 then check if another field is filled in.

If any would be able to provide an example, that would be great.

Specifically, I want to know the syntax to access the field values.

Thanks,
Veeren

There is only limited support for JEXL validation at this time. For field validation, you can access the current field’s content with $value. In your case:
$value == ‘desired_value’

For cross-field checking, you may be able to use pre-requisites on the field validation. Again, for your example, have a pre-req that checks if the other field is NOT NULL. Then set your field validation as desired.

In the worst case, you need to use an Item Validation, which will probably require writing java code.

Thanks. I was able to get the value of the field by using $value in the JEXL statement. However, I couldn’t figure out how to check if another field had been set. In the Prerequisites section there doesn’t seem to be a way to access the data of another filed in the conditional.

The only option that I see that might provide this was Content Item Data…but I haven’t been able to get that to work.

What is Content Item Data used for?

In the past, when I’ve wanted a field to be visible only if another field is set, I’ve had to add the check in the XML for the editor…but I was hoping that there would be an easier way.

To check if another field exists, use a conditional with the PSXSingleHtmlParameter/fieldname and the operation IS NULL (or IS NOT NULL as applicable.)

Input functions (such as validation) differ from output functions (such as visibility) because the data access is different. For input, all fields can be accessed as html parameter types. This is not the case for output.

Content Item data will actually load an item and provide access to any of that item’s fields. This is generally not useful for content editors because you can get into an infinite loop quite easily.

I’m attempting to use field validation to validate that a date entered into a field is no more than a year away (i.e. not later than one year from today). Has anyone done something like this? I have tried JEXL, and am using $value to get the value of the date field, but I can’t seem to get today’s date (plus one year) in that field validation JEXL context. There doesn’t seem to be a way to call the equivalent of the Velocity tools $tools.date.getCalendar() to get today’s date (never mind adding one year).

Anyone have any pointers for me?

Thanks,
Kathleen