decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.9k stars 3.04k forks source link

Can't access nested lists or objects in preview templates #3485

Open jonathansgardner opened 4 years ago

jonathansgardner commented 4 years ago

Is your feature request related to a problem? Please describe. I can't access the data from a nested list widget using the widgetsFor function in my preview template

Describe the solution you'd like I have a list widget that is nested inside of an object widget which I am unable to access in order to display in my preview template using the widgetsFor function

i.e.

# config.yml

...

  - name: about
     label: About
     widget: object
     fields:
       - name: links
          label: Links
          widget: list
          fields:
            - { name: title, label: Link text, widget: string }
            - { name: url, label: URL, widget: string }
jonathansgardner commented 4 years ago

I managed to bypass this by converting the immutable object to json using entry.getIn([ 'data'] ).toJS() It still seems like there should be a way to call widgetsFor on a nested object or list. Maybe by passing in an array i.e. widgetsFor(['about','links])

smashercosmo commented 3 years ago

Having the same problem. Can't find a way to get widgets for nested object. @erezrokah is it even possible?

neumannjan commented 3 years ago

+1. same issue

pkscout commented 3 years ago

I've run into this as well. converting the immutable to JSON works, but it's kind of a mess, especially when you first create a new item that you had to do this way. The API calls seem to have some built-in way of handling the fact that the data is empty, and you have to recreate all that yourself with the JSON.

chrisleyva commented 2 years ago

I think I'm running into the same issue.

image

I'm following the docs here: https://www.netlifycms.org/docs/customization/#lists-and-objects And I can't seem to find the right combination of widgetsFor and getIn to get the individual fields in the nested Address object widget.

As @jonathansgardner mentioned, using toJS() seems like a ~decent~ workaround.