diff --git a/editors/demo/src/HHMI/HHMI.js b/editors/demo/src/HHMI/HHMI.js index 1b9ce865f386cfeb6241f51e97f78f3652137516..19ab37c7bd3d70f8d215612b458ac567b67731be 100644 --- a/editors/demo/src/HHMI/HHMI.js +++ b/editors/demo/src/HHMI/HHMI.js @@ -167,10 +167,11 @@ const Hhmi = () => { ref={editorRef} customValues={{ showFeedBack: submitted, testMode }} fileUpload={file => renderImage(file)} - value={content} + // value={content} + targetFormat="JSON" readonly={readOnly} layout={HhmiLayout} - // onChange={source => console.log(source)} + onChange={source => console.log(source)} /> </> ); diff --git a/wax-questions-service/src/NumericalAnswerService/components/ExactAnswerComponent.js b/wax-questions-service/src/NumericalAnswerService/components/ExactAnswerComponent.js index ac9002e361a9c300f467f9b166480420309c735d..a9e8452d8ba20247a730b36798f9eff37e746cdb 100644 --- a/wax-questions-service/src/NumericalAnswerService/components/ExactAnswerComponent.js +++ b/wax-questions-service/src/NumericalAnswerService/components/ExactAnswerComponent.js @@ -1,6 +1,6 @@ -import React, { useRef, useState } from 'react'; +import React, { useRef, useState, useContext } from 'react'; import styled from 'styled-components'; -import { DocumentHelpers } from 'wax-prosemirror-core'; +import { DocumentHelpers, WaxContext } from 'wax-prosemirror-core'; const AnswerContainer = styled.div` display: flex; @@ -26,7 +26,9 @@ const ValueInnerContainer = styled.div` flex-direction: column; `; -const ExactAnswerComponent = () => { +const ExactAnswerComponent = ({ getPos, node }) => { + const context = useContext(WaxContext); + const { activeView } = context; const [exact, setExact] = useState(''); const [marginError, setMarginError] = useState(''); @@ -40,12 +42,37 @@ const ExactAnswerComponent = () => { .replace(/^0[^.]/, '0'); }; + const SaveValuesToNode = () => { + const allNodes = getNodes(context.pmViews.main); + allNodes.forEach(singleNode => { + if (singleNode.node.attrs.id === node.attrs.id) { + const obj = { + exactAnswer: onlyNumbers(exactRef.current.value), + marginError: onlyNumbers(errorRef.current.value), + }; + + context.pmViews.main.dispatch( + context.pmViews.main.state.tr.setNodeMarkup( + singleNode.pos, + undefined, + { + ...singleNode.node.attrs, + answersExact: obj, + }, + ), + ); + } + }); + }; + const onChangeExact = () => { setExact(onlyNumbers(exactRef.current.value)); + SaveValuesToNode(); }; const onChangeError = () => { setMarginError(onlyNumbers(errorRef.current.value)); + SaveValuesToNode(); }; return ( diff --git a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js index 8d05991f482d633391cdfd437b9caf52893a00bb..8abd8c6b8b55943d1105ece30022c19156ec2d01 100644 --- a/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js +++ b/wax-questions-service/src/NumericalAnswerService/components/NumericalAnswerContainerComponent.js @@ -106,13 +106,13 @@ export default ({ node, view, getPos }) => { <NumericalAnswerOption> {!options[node.attrs.id] && <>No Type Selected</>} {options[node.attrs.id]?.numericalAnswer === 'exactAnswer' && ( - <ExactAnswerComponent /> + <ExactAnswerComponent getPos={getPos} node={node} /> )} {options[node.attrs.id]?.numericalAnswer === 'rangeAnswer' && ( - <RangeAnswerComponent /> + <RangeAnswerComponent getPos={getPos} node={node} /> )} {options[node.attrs.id]?.numericalAnswer === 'preciseAnswer' && ( - <PreciseAnswerComponent /> + <PreciseAnswerComponent getPos={getPos} node={node} /> )} </NumericalAnswerOption> {!testMode && !(readOnly && feedback === '') && ( diff --git a/wax-questions-service/src/NumericalAnswerService/components/PreciseAnswerComponent.js b/wax-questions-service/src/NumericalAnswerService/components/PreciseAnswerComponent.js index 38c34b2eabc0d492ddb1b027adaa1a44ae6c4027..506230e5a8a62403ee9b9659d90b2710e729f56a 100644 --- a/wax-questions-service/src/NumericalAnswerService/components/PreciseAnswerComponent.js +++ b/wax-questions-service/src/NumericalAnswerService/components/PreciseAnswerComponent.js @@ -33,7 +33,7 @@ const PreciseAnswerComponent = () => { const onlyNumbers = value => { return value - .replace(/[^0-9.]/g, '') + .replace(/[^0-9.;]/g, '') .replace(/(\..*?)\..*/g, '$1') .replace(/^0[^.]/, '0'); }; diff --git a/wax-questions-service/src/NumericalAnswerService/schema/NumericalAnswerContainerNode.js b/wax-questions-service/src/NumericalAnswerService/schema/NumericalAnswerContainerNode.js index b110d5f2431a6416dfaaf7a37aef3cd7d53a4e84..e70db45d3b9e237d0a1a168e9dd306d8a72e63e3 100644 --- a/wax-questions-service/src/NumericalAnswerService/schema/NumericalAnswerContainerNode.js +++ b/wax-questions-service/src/NumericalAnswerService/schema/NumericalAnswerContainerNode.js @@ -4,7 +4,7 @@ const NumericalAnswerContainerNode = { class: { default: 'numerical-answer' }, feedback: { default: '' }, answerType: { default: '' }, - answers: { default: [] }, + answersExact: { default: [] }, }, group: 'block questions', atom: true, @@ -14,7 +14,7 @@ const NumericalAnswerContainerNode = { tag: 'div.numerical-answer', getAttrs(dom) { return { - answers: JSON.parse(dom.getAttribute('answers')), + answersExact: JSON.parse(dom.getAttribute('answersExact')), id: dom.getAttribute('id'), class: dom.getAttribute('class'), feedback: dom.getAttribute('feedback'), @@ -29,7 +29,7 @@ const NumericalAnswerContainerNode = { { id: node.attrs.id, class: node.attrs.class, - answers: JSON.stringify(node.attrs.answers), + answersExact: JSON.stringify(node.attrs.answersExact), feedback: node.attrs.feedback, answerType: node.attrs.answerType, },