Netlify-cms: Date widget inside list widget not showing default date value

Created on 18 Feb 2018  路  8Comments  路  Source: netlify/netlify-cms

- Do you want to request a feature or report a bug?

- What is the current behavior?

- If the current behavior is a bug, please provide the steps to reproduce.

- What is the expected behavior?

- Please mention your CMS, node.js, and operating system version.

- Please link or paste your config.yml below if applicable.

I have a list widget with each item containing multiple date fields. However, all date fields other than the last field are initially blank instead of showing the default value (the current date in this case). I am using CMS version 1.2.0 according to my browser console.

Here is a link to my config.yml:

config.yml

extensionwidgets good first issue bug confirmed

All 8 comments

Hi @thebetternewt
I have just tried to replicate the problem, but I don't see any issues. All the dates are displaying as expected. Are you still having issues?

This seems to be fixed in 1.3.5, not sure where the fix actually occurred. Please comment if you're still able to reproduce.

Hi. Sorry for the delayed response. Yes I thought this issue was already confirmed and fixed. I did not realize the issue was still open. It has been working for a while now. Thanks your your help!

I can still reproduce this in v1.5.0 using the original config, although I couldn't in v1.3.5. I'm guessing the fix was a side effect of the regression fixed in #1210. Unfortunately, fixing that regression broke this again.

collections:
  - label: "Settings"
    name: "Settings"
    files:
      - name: "date_settings"
        label: "Date Settings"
        file: "data/date_settings.json"
        description: "Set blackout dates"
        fields:
          - label: "Blackout Dates"
            name: "blackout_dates"
            widget: "list"
            fields:
              - {label: "Note", name: "note", widget: "string"}
              - {label: "Start Date", name: "start_date", widget: "date"}
              - {label: "End Date", name: "end_date", widget: "date"}

When a new list item is created, the Date widget calls onChange to set its default.

The nested default is set using this code:
https://github.com/netlify/netlify-cms/blob/1a3454f244b1e1a190f24fe2acfb9b1583446bc6/src/components/EditorWidgets/List/ListControl.js#L163

For some reason, when the list is first being created, getObjectValue returns an empty Map on every call, so instead of adding the new value to the Map, only the one just set remains. Therefore, when there are multiple widgets in the list item, only the last one will have remain (1 will overwrite 2, 2 will overwrite 3, etc.).

Is the Redux action asynchronous in this case? If so, when we call onChange (DRAFT_CHANGE_FIELD), it's not necessarily going to update before the next widget sets its value.

@erquhart can we now close this?

@erquhart ping!!!

@barthc sorry about that, yes!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

emckay picture emckay  路  3Comments

BerkeleyTrue picture BerkeleyTrue  路  3Comments

TomPichaud picture TomPichaud  路  3Comments

ghost picture ghost  路  3Comments

kalwalt picture kalwalt  路  3Comments