You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Json field with a jsonSchema, it's currently impossible to add multiple items with the same JsonField URI in the admin panel.
For instance, if I have a ui-block (say featuresJsonBlock) containing a json field with a specific jsonSchema, I can only add ONE featuresJsonBlock on my page/post. If I try to add another featuresJsonBlock, monaco editor will throw an error similar to what's described here: atularen/ngx-monaco-editor#48 or microsoft/monaco-editor#926 .
I solved it on my end by creating a custom json field and edited the existing code in @payloadcms/ui/src/fields/JSON/index.tsx slightly.
But perhaps this could be added to payload/ui itself.
const handleMount = useCallback(
(editor, monaco) => {
if (!jsonSchema) {
return
}
const existingSchemas = monaco.languages.json.jsonDefaults.diagnosticsOptions.schemas || []
// if the schema is already in the existingSchemas, don't add it again
if (existingSchemas.some(schema => schema.uri === jsonSchema.uri)) {
return
}
const modelUri = monaco.Uri.parse(jsonSchema.uri)
const model = monaco.editor.createModel(JSON.stringify(value, null, 2), 'json', modelUri)
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
enableSchemaRequest: true,
schemas: [...existingSchemas, jsonSchema],
validate: true,
})
editor.setModel(model)
},
[jsonSchema, value],
)
While the solution you describe will indeed work, it is a little bit unsatisfactory because, as a result, it would prevent subsequent JSON fields from having schema validation applied to them. I'm honestly not too sure about this one. If you have multiple JSON fields, a workaround is to simply provide them different uri's/filenames to prevent this from happening. Although, that will not work in something like an Array field.
Describe the Bug
When using Json field with a jsonSchema, it's currently impossible to add multiple items with the same JsonField URI in the admin panel.
For instance, if I have a ui-block (say featuresJsonBlock) containing a json field with a specific jsonSchema, I can only add ONE featuresJsonBlock on my page/post. If I try to add another featuresJsonBlock, monaco editor will throw an error similar to what's described here: atularen/ngx-monaco-editor#48 or microsoft/monaco-editor#926 .
I solved it on my end by creating a custom json field and edited the existing code in @payloadcms/ui/src/fields/JSON/index.tsx slightly.
But perhaps this could be added to payload/ui itself.
Link to the code that reproduces this issue
https://github.com/payloadcms/payload/blob/466f109152bc6bf9a67e7d7bafd38c7d57a881de/packages/ui/src/fields/JSON/index.tsx
Reproduction Steps
ModelService: Cannot add model because it already exists
Which area(s) are affected? (Select all that apply)
area: ui
Environment Info
The text was updated successfully, but these errors were encountered: