I’m trying to create a widget to choose an article from an existing set of articles. I’m using a “list” of “relation” widget. So far, it works when I set value_field
to “title”, but not when I set value_field
to “slug”. When set to “slug”, the autosuggestion dropdown only shows one item and defaults to the first in the collection (alphabetically). Although I am able to still search an article, the selection is not saved. I’m using Hugo and need to reference by slug.
This works:
collections:
- label: "Pages"
name: "pages"
files:
- label: "Homepage"
name: "homepage"
file: "content/_index.md"
fields:
- {label: "Title", name: title, widget: string}
- {label: "Profile Photo", name: profile_photo, widget: image, choose_url: false}
- {label: "Bio", name: body, widget: markdown}
- label: "Top Posts"
name: "top_posts"
widget: "list"
summary: '{{title}}'
fields:
- label: "Post"
name: "featured_entries"
widget: "relation"
collection: "entries"
max: 4
search_fields: ["title", "publications", "topics"]
display_fields: ["{{title}}"]
value_field: "title"
This does not work:
collections:
- label: "Pages"
name: "pages"
files:
- label: "Homepage"
name: "homepage"
file: "content/_index.md"
fields:
- {label: "Title", name: title, widget: string}
- {label: "Profile Photo", name: profile_photo, widget: image, choose_url: false}
- {label: "Bio", name: body, widget: markdown}
- label: "Top Posts"
name: "top_posts"
widget: "list"
summary: '{{title}}'
fields:
- label: "Post"
name: "featured_entries"
widget: "relation"
collection: "entries"
max: 4
search_fields: ["title", "publications", "topics"]
display_fields: ["{{title}}"]
value_field: "slug"