Unable to create relation widget : Cannot read property 'hits' of undefined

Hi all

I am a newbie to netlify-cms, I am trying to build a simple relation widget as per the documentation but i am facing this issue Cannot read property ‘hits’ of undefined

The following is my config.yml file:

backend:
  name: git-gateway
  branch: master
local_backend: true
media_folder: public/img
public_folder: img
collections:
  - name: "pages"
    label: "Pages"
    files:
    - label: "Home"
      name: "home"
      file: "content/home.md"
      fields:
        - { label: "Title", name: "title", widget: "string"}
        - { label: "Publish Date", name: "date", widget: "datetime" }
        - { label: "Body", name: "body", widget: "markdown"}
        - label: 'Cats'
          name: "cats"
          widget: list
          fields:
            - { label: "Name", name: "name", widget: "string"}
            - { label: "Description", name: "description", widget: "text"}
  - name: "menus"
    label: "Menus"
    folder: "content/menus"
    create: true
    fields:
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Accessible Title", name: "srTitle", widget: "string"}
      - {label: "Menu URL", name: "menuUrl", widget: "string"}
      - {label: "Is menu inline ?", name: "menuInline", widget: "boolean", default: true}
      - {label: "Is menu special ?", name: "menuSpecial", widget: "boolean", default: false, required: false}
      - {label: "Menu Order", name: "menuOrder", widget: "number"}
  - name: "settings"
    label: "Settings"
    files:
      - label: "General Settings"
        name: "generalScettings"
        file: "content/settings/general.md"
        fields:
          - {label: "Website title", name: "siteTitle", widget: "string"}
          - {label: Logo alternate title, name: logoAltTitle, widget: string}
      - label: "Footer Settings"
        name: "footerSettings"
        file: "content/settings/footer.md"
        fields:
          - label: "Test relation"
            name: "relationTest"
            widget: "relation"
            collection: "menus"
            value_field: "title"
            search_fields: ["title"]
            display_fields: ["title"]

Can you share the Github repository so I can have a look?

@tomrutgers This is the link to the repo https://github.com/senthilkumar04/code-sharing-tree

It seems like the changes in this PR are causing some trouble.

When you follow the docs for the relation widget, like you did, you end up with errors like config should have required property 'valueField'. You didn’t get to that point because you were using an old version of the CMS, 2.9.7. The docs state that you should use snake case value_field, but the relation widget still asks for a valueField. CC @erez

I opened a PR in your repo with some fixes

2 Likes

@tomrutgers Thank for the fix, so from now onwards we have to start using camelcase instead of snake case in the config.yml file. please correct me if I am wrong?

I think the long term plan is to switch to snake case, but for now you should keep it camelcase. It will be backward compatible when an update follows, I suppose.

Thanks @tomrutgers, there is a standing issue with the CMS docs that they represented the latest code on the default branch and not the published version of the CMS.
We’ll try to get a new version published as soon as possible.

Is it settled in this release then @erez?

@tomrutgers Hi Tom, this is a different question but related to the relation widget. Can we create a relation widget that should list the files in the files collection type? Let us assume that we have several files in a files collection type. Can we list those files in a relation widget? I tried making several changes in the config to achieve the behavior which I asked but there is no luck. Can you please assist me if any way to achieve it? Thanks in advance :slight_smile:

Yes it should be resolved in that release.