ideas icon indicating copy to clipboard operation
ideas copied to clipboard

Require this field OR that field

Open plagasul opened this issue 4 years ago • 5 comments

The idea would be to be able to require a field OR another field. One or the other, not necessarily both.

For example, on the following blueprint I need either a cover image to be provided, or at least one image on the images section, but not both.

cover:
    type: files 
    # require: true
...
images:
    type: files
    # min: 1

The syntax could be something like:

cover:
    type: files 
    require: 
        or: images
...
images:
    type: files
    min:
        - 1
        or: cover

...this particular example mixes 'required' and 'min', but the idea is the same.

plagasul avatar Aug 08 '20 13:08 plagasul

You possible mean when → then feature, right? https://github.com/getkirby/ideas/issues/257

afbora avatar Aug 08 '20 17:08 afbora

Hello @afbora , I don't see how the when -> then feature could be used to do what I mean here.

What I mean is to extend the actual 'require' field option in a way that allows to require any field among a number of fields. For example among field A, B and C, the user needs to fill at least one, any of them. The user can fill two or three, but only one (any) is 'required'.

Is that clear?

Thanks

plagasul avatar Aug 09 '20 15:08 plagasul

With when/then, you could configure something like this:

when:
  - test:
      otherField: ''
      anotherField: ''
    comparison: and
    then:
      required: true
    otherwise:
      required: false

lukasbestle avatar Aug 09 '20 15:08 lukasbestle

Yes, that does seem a way to accomplish the same, although quite verbose considering all that code would need to go on the three fields in your example. Is that final syntax?

I would still prefer a simpler syntax such as

require:
  or: otherfieldname

...which would be more close to what we already do, and specific to require instead of a meta when/then condition train.

Cheers!

plagasul avatar Aug 09 '20 17:08 plagasul

I agree that the syntax is more verbose, but it's also a lot more flexible.

The point is: If we can implement one feature that covers many use-cases, that's a lot better than individual features that make both the blueprint syntax and the implementation way more complex. Also we would duplicate functionality, which will create edge-cases that don't work as expected.

Is that final syntax?

No, it's the current state of the discussion.

lukasbestle avatar Aug 09 '20 18:08 lukasbestle