Relation Widget Multi Select

My goal is to allow a user to relate a given item in collection A, to multiple items in collection B. It looks like the built in relation widget has support for this with the multiple field, in the docs here: Widgets | Netlify CMS | Open-Source Content Management System

This doesn’t seem to work like I expect it to. I’m sure someone else has done something similar before, but I have not yet found it anywhere online. Am I misconfiguring the relation widget, or is there some kind of better approach using the selection widget?

Thanks,
Nick

Yeah, that’s be possible! Be aware that the relation widget only works with folder collections. Here’s an example:

collections:
  - label: Posts
    name: posts
    folder: data/posts/
    create: true
    slug: '{{title}}'
    fields: 
      - {label: Title, name: title, widget: string}
      - label: "Author"
        name: "author"
        widget: "relation"
        collection: "authors"
        searchFields: ["author_name"]
        valueField: "author_name"
        multiple: true

  - name: authors
    label: Authors
    folder: data/authors/
    create: true
    slug: '{{title}}'
    identifier_field: author_name
    fields:
      - {label: Name, name: author_name, widget: string}

You could also use the list widget in combination with a nested relation widget. The UI is a bit more complex but it works just as well.

3 Likes

thanks for sharing @tomrutgers !

No problem @perry, happy to help!