LiamMartens / sanity-plugin-intl-input

Intl input for Sanity with a cleaner UI than a default solution
MIT License
111 stars 22 forks source link

A lot of properties on fields of an i18n object or document won't work #94

Open hrisng opened 2 years ago

hrisng commented 2 years ago

Description: Properties that requires coordination from Sanity Studio like validation, hidden, initialValue, fieldsets will stop working if I set the i18n option to true on a document or object. This will only affect the direct child fields of said document or object. Fields one level deeper (inside another child object) will have their normal behaviour back.

Example:

  {
      name: 'localizedContent',
      type: 'object',
      title: 'Nội dung đa ngôn ngữ',
      options: { i18n: true },
      fields: [
        {
          name: 'hasCallToAction',
          type: 'boolean',
          title: 'Hiển thị Call To Action',
          initialValue: false,
        },
        {
          name: 'callToAction',
          type: 'object',
          title: 'Call To Action',
          hidden: true,
          options: {
            collasible: true,
            collapsed: true,
          },
          fields: [
            { title: 'Text thể hiện', name: 'displayText', type: 'string' },
          ],
        },

In the above snippet, initialValue on hasCallToAction will not be set, and callToAction field is not hidden. However, things specified in options like collapsible will still work correctly.

Expected behaviour: These properties are crucial and the plugin should not interfere with that.

What I found: An i18n object in the above case will normally have this shape:

localizedContent: {
  vi_VN: {},
  en_EN: {}
}

Now what happen when I set initialValue on hasCallToAction is that it gonna get this shape:

localizedContent: {
  vi_VN: {},
  en_EN: {},
  hasCallToAction: false <------- It get populated here instead of inside the appropriate locale
}

^ Understandably, because of this, Sanity Studio is not being able to correctly populate the initialValue in the input. Somehow it's the same case with hidden , validation , fieldset and the like.

Environment: Sanity: 2.21.6 sanity-plugin-intl-input: 5.5.0

LiamMartens commented 2 years ago

@hrisng I am looking at this - it's not the easiest to fix as it concerns internal Sanity mechanics