Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Require this field OR that field #595

Open
plagasul opened this issue Aug 8, 2020 · 5 comments
Open

Require this field OR that field #595

plagasul opened this issue Aug 8, 2020 · 5 comments

Comments

@plagasul
Copy link

plagasul commented Aug 8, 2020

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
Copy link
Member

afbora commented Aug 8, 2020

You possible mean when → then feature, right? #257

@plagasul
Copy link
Author

plagasul commented Aug 9, 2020

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
Copy link
Member

lukasbestle commented Aug 9, 2020

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

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

@plagasul
Copy link
Author

plagasul commented Aug 9, 2020

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
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants