How to validate to Dates with DateTimeRangeValidator


(Erich Manser) #1

I found the documentation for validation: https://neos.readthedocs.io/en/stable/References/Validators/Flow.html?highlight=earliestDate#datetimerangevalidator.

What I would like to do is validate that property begin is not empty and property end is not prior property begin. Validation for begin is fine. But validation vor end does not do anything. Setting earliestDate: now/P2W has no effect at all.

  properties:
begin:
  type: DateTime
  ui:
    label: 'Start'
    inspector:
      group: duration
      position: 10
      editorOptions:
        format: 'd-m-Y H:i'
  validation:
    'Neos.Neos/Validation/NotEmptyValidator': []
end:
  type: DateTime
  ui:
    label: 'Ende'
    inspector:
      group: duration
      position: 20
      editorOptions:
        format: 'd-m-Y H:i'
  validation:
    'Neos.Neos/Validation/DateTimeRangeValidator':

Is there any example for this?


(Martin Ficzel) #2

Validation will not work that way since property validators only check the single value. It might be possible to create a valitator for the whole node that will check both values and their relation but that would still not work nicely since it would not be reflected properly in the ui and would not help editors much.

What would work is understanding the range as a single value of Type „Array“ (with the keys „start“ and „end“) and create a specific DateTimeRange inspector-editor for that. It could internally use two dateTime Editors and ensure the proper relation between them.

This is an example how custom editors are implemented https://neos.readthedocs.io/en/stable/ExtendingNeos/CustomEditors.html