-
-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boolean options won't update to false #96
Comments
Can you elaborate your problem by sending some code-example. It will be quite helpful to understand it |
|
My application contains lessons for the user to code in the CodeMirror editors. Lesson has a parameter for readOnly for specific editors. If one lesson was set to readOnly = true, then when loading a different lesson that has readOnly = false, it won't overwrite the true, so it stays locked. I fixed it by changing if clause in index.js on line 49 (now 50) from: if (opt[name] && JSON.stringify(opt[name])) {
instance.setOption(name, opt[name]);
} to: if ((opt[name] || opt[name] === false) && JSON.stringify(opt[name])) {
instance.setOption(name, opt[name]);
} Here is a snippet of my code: export const ApplicationPage: React.FC = () => {
const [lesson, setLesson] = useState<{ [x: string]: string } | null>(null);
const fetchLesson = (_userId: number, _lessonId: number) => {
const getPromiseLesson = async () => {
const l = await window.fetch("/lesson/" + _lessonId, {
method: "GET"
}).then(response => response.json())
setLesson(l)
const getPromiseSave = async () => {
const s = await window.fetch("/latest-save/" + _userId + "/" + _lessonId, {
method: "GET"
}).then(response => response.json())
if (s != "0") {
setComment("")
setLesson(({...l, ...s}));
setJavaOut(s["j_out"])
setPythonOut(s["p_out"])
}
}
const promiseSave = getPromiseSave()
promiseSave.catch()
};
const promiseLesson = getPromiseLesson()
promiseLesson.catch()
};
useEffect(() => {
fetchLesson(userId, lessonId)
}, [userId, lessonId]
);
return (
<JavaApp lesson={lesson}/>
)
}
interface Props {
lesson: { [x: string]: string }
}
const _JavaApp: React.ForwardRefRenderFunction<JavaAppHandle, Props> = ({lesson}: Props, ref) => {
let javaTest = useRef<CodeMirror>(null);
return (
<CodeMirror
ref={javaTest}
value={lesson["j_test"]}
options={{
theme: "darcula",
keyMap: "sublime",
mode: "java",
readOnly: lesson["j_test_lock"]
}}
/>
)
} |
When I set CodeMirror options readOnly on true and then update it to false it doesn't update and the editor stays locked. I'm passing the value in as a react prop.
I assume that it doesn't get through the if in index.js on line 49.
The text was updated successfully, but these errors were encountered: