question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom Field - Map

See original GitHub issue

Hi there 👋

I am trying to have my schema feature an array of contents that can be of different types, as the example below shows:

// Expected json output
{
  ...
  contents: [
    {
      type: 'lesson-video',
      attributes: {
        video: 'https://...',
      }
    },
    {
      type: 'exercise-free-text',
      attributes: {
        question: '...'
      }
    },
    {
      type: 'exercise-multi-choice',
      attributes: {
        question: '...',
        answers: [ ... ]
      }
    },
    {
      type: 'lesson-audio',
      attributes: {
        audio: 'https://...',
        text: '...'
      }
    },
    {
      type: 'exercise-multi-choice',
      attributes: {
        question: '...',
        answers: [ ... ]
      }
    },
    {
      type: 'recap',
      attributes: {
        learnings: [ ... ]
      }
    },
  ]
  ...
}

The goal is for my content managers to be able to add contents to the array and have each content featuring dynamic attributes fields that depend on the content type that has first been selected.

I have tried using Conditional fields from properties and Custom fields but wasn’t able to set this up.

Can someone help with that ? 🙏

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
fgatti675commented, Apr 1, 2021

That would be awesome! There is 2 ways to go:

  • The simplest one is you develop a CustomField of type array. If the types you want to use in your array are preset you can code them inside your component. Otherwise, if you want to make it generic and inject the components externally you can use the fieldProps like in this example (just a suggestion of how you could implement it)
...
        content: {
            title: "Content",
            dataType: "array",
            config: {
                field: ArrayOfTypedMapsField, // This is the field you can develop
                fieldProps: { // This is an example of how you could define your internal types
                    discriminatorName: "type",
                    contentName: "attributes",
                    options: [
                        { 
                            discriminator: "lesson-video",
                            properties: { ... } // same as you would define properties in a "map"
                            validation: {...} // same as you would define validation in a "map"
                        },
                        ...
                    ]
                    
                }
            }
        },
 ...
  • The second option is to build something similar to what I have mentioned before directly into the CMS core; it would be much harder for you since it would require understanding of the internals. Also it would take longer to be released in production.

I would suggest to go with the first option, and develop something that works for you. Then you can share it with me and we see how we integrate it 😃

I am also working on creating an example custom field that includes other fields inside, and some internal changes to make a nicer API. I will probably have it ready over the weekend!

Let me know if I can help you with anything else

1reaction
fgatti675commented, Jul 29, 2021

Hi everyone!

Just to let you know that the oneOf prop has been added to Array properties so this feature is now implemented natively in version 0.45.1

You can check a sample implementation in: https://github.com/Camberi/firecms/blob/master/example/src/SampleApp/schemas/products_schema.tsx#L62 or the docs: http://firecms.co/docs/api/interfaces/arrayproperty#oneof

I am pretty excited of finally integrating this one! Hope it works for you too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Map - ACF
The Google Map field provides an interactive map interface for selecting a location. This field type uses the Google Maps JS API to...
Read more >
Customize Salesforce Field Mappings
From Setup, enter the name of the object you want to map the Data.com fields to, for example, Accounts, then select Fields. ·...
Read more >
Custom Fields Mapping | Zendesk Developer Docs
Custom Fields Mapping describes how custom fields seen by user (e.g. contact custom field "Role in organisation") are mapped to custom field objects...
Read more >
Map Values for Custom Fields in the Mapper
Based on the type of custom field invoked, you can provide the details (internalId and scriptId) of the custom field being mapped and...
Read more >
Map Custom Fields Importing in Outlook 2013
I'm trying to import a .csv file into Outlook 2013 Contacts and get as far as the "Map Custom Fields" window. Under the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found