EmCeeEs / netlify-cms-i18n

Internationalisation (i18n) for netlify CMS.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

widget type 'i18n-object` not updating/saving value

xposedbones opened this issue · comments

Everything else works great but I'm having trouble with the object type. I can't update or enter text at all. I managed to show text by manually editing the markdown file but I can't edit it.

Here's my config:

  • netlify-cms-app 2.15.59
  • netlify-cms-core 2.54.0

The CMS config is loaded manually instead of with the standard config.yml, don't think this is the issue since every other fields seems to work great.

Here's the field config:

export const HeroBannerFields: NetlifyField = {
  label: 'HeroBanner',
  name: 'herobanner',
  widget: 'i18n-object',
  fields: [
    { label: 'Text', name: 'text', widget: 'string' },
    { label: 'Subtitle', name: 'subtitle', widget: 'string' }
  ]
}; 

and here's the bug in action

Screen.Recording.2021-12-01.at.5.07.32.PM.mov

The preview is only showing the last character that was entered. Let me know if you need more info

I forked the repo and took a look around and found a few things that can help (I wasn't able to fix it – yet)

the onChange event is not fired when it's an object, I was able to get it firing by changing the Widget.control in src/widget/index.tsx to this

{Widget.name === 'object' ? (
  <Widget.control
    {...props}
    ref={ref}
    key={locale}
    onChangeObject={handleChange}
    value={getValue()}
  />
) : (
  <Widget.control
    {...props}
    ref={ref}
    key={locale}
    onChange={handleChange}
    value={getValue()}
  />
)}

I could not get the control to update the text though but it's a step in the right direction.

Regarding the preview. I looked at netlifycms repo and found that the object preview is not like the other widget. It needs a prop called field instead of the value every other widget uses (https://github.com/netlify/netlify-cms/blob/master/packages/netlify-cms-widget-object/src/ObjectPreview.js)

Hope this helps