I must not be understanding this correctly as iām looking for something i kind of just assumed would be an option.
When i define the fields for a model, i want to be able to add a field, called details, and have it display the fields defined in the detailsBlock i set up.
The details block is used across lots of models, because the fields are the same.
The problem is, in the content editor, if i add a modular content field, there is no option to force an instance of the block. Which i should be able to do.
Instead it requires the editor to click add block, which they shouldnāt have to do.
Infact, i should be able to add multiple fields to a model, either pointing to the same BlockType or different blocktypes, and appear by default in the editor for the model.
I just canāt find a field option that does that?
I have noted, that the fieldsets option, kind of does what i want from a visual perspective but doesnāt allow you to have fields nested with the same key as other fields in other fields sets. Which makes sense, given the fieldset is purely visual and doesnāt actually nest the fields in the json output. (which could/should also be an option)
Iām under the impression that the blocks functionality has been developed with more of the visual side in mind, rather than the schema of the actual resulting model.
Ok, i created a plugin as a field addon (under presentation) that basically lets you force force the blocks to be added when creating a new model. Will share it.
So it might be DatoCMS returning something unexpected, or if youāre building locally then it might be webpack messing with the ⦠operator. Iām not sure myself. I litterally just bashed this together over the weekend.
Ok, iāve wrapped in a try/catch but i canāt replicate the error so i hope it wraps your error up.
The [ā¦param] failes if it gets an object or a number. So iām wondering what are valid fieldValues.
Iāve also noticed a bug, where if a model has multiple instances of a block, the presentation view gets inundated with repeat instances of that blocks switcher.
Iām hoping that the SDK v2, gets updated to pass the field parameters data into the ctx object, because currently you canāt tell what field your editing. Hence having to loop through all the field validators for the whole model, rather than just for the field you editing.
In general, Iāll try to sum up my 2C (sorry for the long reply! )
If the Modular Content field has a validation (ie. āat least 2 blocksā, or āexactly 1 blockā) AND thereās only one type of block you can add, it would make sense that DatoCMS natively creates some empty blocks for you, I agree with you. Weāll try to prioritize this request, hopefully it will be shipped soon! In the meantime, plugins are fine, thatās what theyāre for
Talking about plugins, a modular field value should always be an array OR null, and spreading a null value is not permitted:
So you need to do something like [...(fieldValue || []), newBlock]
Since you can use the same manual field extension on multiple field types, it makes sense to add some additional information in the ctx of the renderManualFieldExtensionConfigScreen hook. It cannot be a full Field object though, as it might not even exist if youāre creating a brand new field.
Iāve just released v0.3.20 of the datocms-plugin-sdk package with the following new properties available in the ctx of renderManualFieldExtensionConfigScreen hooks:
It was a bug with my plugin code that displayed multiple switches with the same block name. I think i had two fields applied to my model, both fields using validators that had the same block added.
Because the Plugin Config component doesnāt tell you which field your editing on the ctx object, I iterated through the whole model description. As such it lists the same validator twice.
Now that youāve updated the SDK to pass through the pendingField iāll see about resolving that.
Talking about plugins, a modular field value should always be an array OR null , and spreading a null value is not permitted:
So you need to do something like [...(fieldValue || []), newBlock]
Added a modula field, applied a block to the validators, added the addon and i get the following errors.
I updated the package.json to the new versions, both the sdk and ui looked like they had changed.
Had a couple of complaints in the Plugin config component.
Cleared npm, lock files and restarted all instances of the plugin and browser cache.
index.js:11 TypeError: Cannot read properties of undefined (reading 'origin')
at AdminArea-J72GJJGT.js:1:83746
at Array.map (<anonymous>)
at Ko (AdminArea-J72GJJGT.js:1:83693)
at AdminArea-J72GJJGT.js:1:84237
at Object.useMemo (chunk-Q7JIQSC3.js:2:59326)
at Object.l.useMemo (chunk-B7G5LW6E.js:1:7075)
at Ag (chunk-5OHDIJPZ.js:1:5620)
at Xo (AdminArea-J72GJJGT.js:1:84230)
at Si (chunk-Q7JIQSC3.js:2:55172)
at va (chunk-Q7JIQSC3.js:4:15080)
@emile.swain Iāve tried to enter your project to reproduce the issue, but the modular content was already deleted so I cannot see the error Iāve tried recreating it and applying the plugin, but no exception.
Can you recreate the situation in which the error occurs on the birely-app project (maybe on a new environment so youāre not blocked by the error)? At that point let me know and Iāll try to solve it, thanks!
seems to work fine now. I think there is occasionally an issue with browser cache or something residual when switching between market place and localhost plugins.
Iām wondering if there is a way to build against the none obsfuscated code so i could read the errors if they happen?