mrkp
July 22, 2020, 6:54am
1
My goal is to allow a user to select multiple options from list widget which I previously created. It looks like the built in relation widget has support for this with the multiple
field, in the docs here: https://www.netlifycms.org/docs/widgets/#relation
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. Is there some kind of better approach using the relation widget?
Thanks
fool
July 24, 2020, 8:51pm
2
Our support team hasn’t tried that configuration so not sure what the answer would be. Maybe @tomrutgers has some clues since he’s pretty CMS-savvy, or else you could try pinging the developers in their slack, linked from here: Community | Netlify CMS | Open-Source Content Management System .
The relation widget indeed has built in support for multiple items using the multiple: true
property. Here’s a basic example:
collections:
- name: posts
label: Posts
folder: data/posts/
create: true
slug: "{{title}}"
fields:
- {name: title, label: Title, widget: string}
- name: categories
label: Categories
widget: relation
collection: "categories"
searchFields: ["name"]
valueField: "name"
displayFields: ["name"]
multiple: true
- name: categories
label: Categories
folder: data/categories/
create: true
slug: "{{name}}"
identifier_field: name
fields:
- {name: name, label: Name}
You can also nest the relation widget in the list widget like so:
collections:
- name: posts
label: Posts
folder: data/posts/
create: true
slug: "{{title}}"
fields:
- {name: title, label: Title, widget: string}
- name: categories
widget: list
field: {
label: "category",
name: "category",
widget: "relation",
collection: "categories",
searchFields: ["name"],
valueField: "name"
}
- name: categories
label: Categories
folder: data/categories/
create: true
slug: "{{name}}"
identifier_field: name
fields:
- {name: name, label: Name}