EmCeeEs / netlify-cms-i18n

Internationalisation (i18n) for netlify CMS.
MIT License
2 stars 2 forks source link

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

Open xposedbones opened 2 years ago

xposedbones commented 2 years ago

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:

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

https://user-images.githubusercontent.com/1087405/144321928-ba2e3a69-c068-4f7c-8739-fda4fd4b9a48.mov

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

xposedbones commented 2 years ago

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