Open papandreou opened 6 years ago
Hadn't tried using lists in an editor component, thanks for raising this.
The issue is that the List widget expects an Immutable List of Immutable Maps for it's values - instead of ['foobar value']
, it wants List[ Map({ foobar: 'foobar value' }) ]
. We should be handling this transformation in the widget I think, but not certain.
For now, you can fix your widget implementation with the following updates:
Make sure Immutable loaded and ready.
Change your fromBlock
function to something like:
fromBlock: function(match) {
const foobars = match[1].split(',').filter(val => val).map(foobar => ({ foobar }));
const obj = {
foobars: Immutable.fromJS(foobars)
}
return obj;
}
Change your toBlock
function to something like:
toBlock: function(obj) {
const foobars = Immutable.fromJS(obj.foobars || [])
return 'SimpleListWidget ' + (foobars.map(entry => entry.get('foobar')).join(',');
},
@erquhart, thanks a lot for the quick reply and the workaround -- I have my original, more complex custom editor widget working now based on it.
I agree that the transformation should be handled by the framework, though.
I just came here to open an issue for the same problem, great that I found this and you're also providing a work around.
I was going around in circles trying to debug this convinced the problem was at my end.
I agree with @papandreou that ideally this transformation would be handled by the framework.
I get this error when nesting lists using the default list
widget. Edit: never mind it was related to this: https://github.com/netlify/netlify-cms/issues/1353.
I had a similar issue and was down to the fact I was using an object widget with just one field.
thumbnails:
display: true
had to change to
display_thumbnails: true
Which makes more sense anyway.
Hope this helps someone that made the same mistake as myself.
:100:
Thanks for adding that @kylekirkby!
Actually leaving this open, should be supported out of the box.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Any updates on this? The bug is affecting me as well... A fix would be nice!
Still no update on this? Impacting me as well.
- Do you want to request a feature or report a bug?
bug
- What is the current behavior?
I have a custom editor component that encapsulates some structured data, particularly a
list
field with amarkdown
widget inside it: https://github.com/papandreou/netlify-test-2/blob/e91791c56ecb441d0867a79f66e79aa678bfd995/admin/index.html#L65-L71This appears to work fine in the editor when I create a new component. The markdown editor expands correctly, and I can add all the
learnings
I want, and expanding/collapsing the widget works fine. When I publish, it also serializes to the format that I would expect: https://raw.githubusercontent.com/papandreou/netlify-test-2/master/lessons/2018-05-22-my-new-lesson.mdHowever, when I load the document again (or switch to markdown mode and back) and try to expand the custom widget, the following error happens, similar to #1353:
From debugging a bit, I can tell that the
fromBlock
method of my custom widget returns the following, which appears to be correct:- If the current behavior is a bug, please provide the steps to reproduce.
It seems like the error is reproducible in a simpler setting that does not depend on my custom patches or the
markdown
widget, so the steps are:SimpleListWidget
to a markdown field in rich text mode- What is the expected behavior?
That the
SimpleListWidget ...
block turns back into a component in rich text mode.- Please mention your versions where applicable.
Netlify CMS version: 1.8.0 Browser version: Chrome 66.0.3359.181/OSX
Node.JS version: 9.5.0 (but doesn't matter as this happens in the browser) Operating System: OSX
- Please link or paste your
config.yml
below if applicable.https://github.com/papandreou/netlify-test-2/blob/1503df31b0cdc59db5739dd846c038db80221858/admin/config.yml