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

save correct value for matching

parent 75dcab3c
No related branches found
No related tags found
1 merge request!399Oen
...@@ -53,14 +53,15 @@ const DropComponent = ({ getPos, node, view }) => { ...@@ -53,14 +53,15 @@ const DropComponent = ({ getPos, node, view }) => {
setSelectedOption(option); setSelectedOption(option);
const allNodes = getNodes(main); const allNodes = getNodes(main);
console.log(allNodes);
allNodes.forEach(singleNode => { allNodes.forEach(singleNode => {
if (singleNode.attrs.id === node.attrs.id) { if (singleNode.node.attrs.id === node.attrs.id) {
main.dispatch( main.dispatch(
main.state.tr main.state.tr
.setMeta('addToHistory', false) .setMeta('addToHistory', false)
.setNodeMarkup(getPos() + 3, undefined, { .setNodeMarkup(singleNode.pos, undefined, {
...singleNode.attrs, ...singleNode.attrs,
answer: option, correct: option.value,
}), }),
); );
} }
...@@ -100,15 +101,5 @@ const DropComponent = ({ getPos, node, view }) => { ...@@ -100,15 +101,5 @@ const DropComponent = ({ getPos, node, view }) => {
export default DropComponent; export default DropComponent;
const getNodes = view => { const getNodes = view => {
const allNodes = DocumentHelpers.findBlockNodes(view.state.doc); return DocumentHelpers.findInlineNodes(view.state.doc);
const matchingOptions = [];
allNodes.forEach(node => {
if (node.node.type.name === 'paragraph') {
node.node.content.content.forEach(optionNode => {
if (optionNode.type.name === 'matching_option')
matchingOptions.push(optionNode);
});
}
});
return matchingOptions;
}; };
...@@ -3,7 +3,8 @@ const matchingOptionNode = { ...@@ -3,7 +3,8 @@ const matchingOptionNode = {
class: { default: 'matching-option' }, class: { default: 'matching-option' },
id: { default: '' }, id: { default: '' },
isfirst: { default: false }, isfirst: { default: false },
answer: { default: {} }, answer: { default: '' },
correct: { default: '' },
options: { default: [] }, options: { default: [] },
}, },
group: 'inline questions', group: 'inline questions',
...@@ -19,7 +20,8 @@ const matchingOptionNode = { ...@@ -19,7 +20,8 @@ const matchingOptionNode = {
id: dom.getAttribute('id'), id: dom.getAttribute('id'),
class: dom.getAttribute('class'), class: dom.getAttribute('class'),
isfirst: JSON.parse(dom.getAttribute('isfirst').toLowerCase()), isfirst: JSON.parse(dom.getAttribute('isfirst').toLowerCase()),
answer: JSON.parse(dom.getAttribute('answer').toLowerCase()), answer: dom.getAttribute('answer'),
correct: dom.getAttribute('correct'),
}; };
}, },
}, },
...@@ -31,7 +33,8 @@ const matchingOptionNode = { ...@@ -31,7 +33,8 @@ const matchingOptionNode = {
id: node.attrs.id, id: node.attrs.id,
class: node.attrs.class, class: node.attrs.class,
isfirst: node.attrs.isfirst, isfirst: node.attrs.isfirst,
answer: JSON.stringify(node.attrs.answer), answer: node.attrs.answer,
correct: node.attrs.correct,
feedback: node.attrs.feedback, feedback: node.attrs.feedback,
}, },
0, 0,
......
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