Skip to content
Snippets Groups Projects
Commit 1fd76927 authored by chris's avatar chris
Browse files

handleChange

parent 07e8f379
No related branches found
No related tags found
1 merge request!348Multiple single
...@@ -33,29 +33,31 @@ const CustomSwitch = ({ node, getPos }) => { ...@@ -33,29 +33,31 @@ const CustomSwitch = ({ node, getPos }) => {
const handleChange = () => { const handleChange = () => {
setChecked(!checked); setChecked(!checked);
const { tr } = main.state;
main.state.doc.descendants((editorNode, pos) => { main.state.doc.descendants((parentNode, parentPos) => {
if (editorNode.type.name === 'multiple_choice_single_correct_container') { if (parentNode.type.name === 'multiple_choice_single_correct_container') {
editorNode.content.content.forEach(element => { parentNode.descendants((element, position) => {
if (element.attrs.id === node.attrs.id) { if (
main.dispatch( element.type.name === 'multiple_choice_single_correct' &&
main.state.tr.setNodeMarkup(getPos(), undefined, { element.attrs.id === node.attrs.id
...element.attrs, ) {
correct: !checked, tr.setNodeMarkup(getPos(), undefined, {
}), ...element.attrs,
); correct: !checked,
} else if (element.attrs.correct) { });
// console.log(element); } else if (
// main.dispatch( element.type.name === 'multiple_choice_single_correct' &&
// main.state.tr.setNodeMarkup(getPos() + 4, undefined, { element.attrs.correct
// ...element.attrs, ) {
// correct: false, tr.setNodeMarkup(parentPos + position + 1, undefined, {
// }), ...element.attrs,
// ); correct: false,
});
} }
}); });
} }
}); });
main.dispatch(tr);
}; };
return ( return (
......
import { v4 as uuidv4 } from 'uuid';
const multipleChoiceSingleCorrectContainerNode = { const multipleChoiceSingleCorrectContainerNode = {
attrs: { attrs: {
id: { default: '' }, id: { default: uuidv4() },
class: { default: 'multiple-choice-single-correct' }, class: { default: 'multiple-choice-single-correct' },
correctId: { default: '' }, correctId: { default: '' },
}, },
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment