monotonic sequence of dates in repeater

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

monotonic sequence of dates in repeater

pumbosha
Hi,

Is it possible to create following validation rule in the repeater ?
I want to have date-selection-control in this repeater, and prevent user to write there date earlier than in previous repeat. I mean I want to dates in all repeats makes monotonic ascending sequence.

regtards
Reply | Threaded
Open this post in threaded view
|

Re: monotonic sequence of dates in repeater

Erik Bruchez
Administrator
You can, although the logic can be a bit tricky:

    (
     for $this in .[string() castable as xs:date] return
     for $that-element in $this/../preceding-sibling::*[1]/*[name() = name($this)] return
     for $that in $that-element[string() castable as xs:date] return
     $that lt $this,
     true()
    )[1]

What the above says is:

- take the current field if it is a valid date
- find the field with same name in the previous iteration if it is a valid date
- if the the fields are dates and the order is correct, then constraint is satisfied
- if the the fields are dates and the order is incorrect, then constraint is not satisfied
- if either field is not a date, the constraint is satisfied (other validations should kick in)

-Erik