getkirby / ideas

This is the backlog of ideas and feature requests from the last two years. Use our new feedback platform to post your new ideas or vote on existing ideas.
https://feedback.getkirby.com
20 stars 0 forks source link

Require this field OR that field #595

Open plagasul opened 4 years ago

plagasul commented 4 years ago

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.

afbora commented 4 years ago

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

plagasul commented 4 years ago

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

lukasbestle commented 4 years ago

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

when:
  - test:
      otherField: ''
      anotherField: ''
    comparison: and
    then:
      required: true
    otherwise:
      required: false
plagasul commented 4 years ago

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!

lukasbestle commented 4 years ago

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.