-
Notifications
You must be signed in to change notification settings - Fork 22
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
v-if condition ruins the json editor visualization #85
Comments
Thank you ❣️ Yes, the 🏷️ latest v0.13.2 release fixes this issue! 🎉 |
You can support this repository by giving it a Star, thanks. |
Certainly, I had already put my star on the repository, I will spread the word on social media. |
Still a question: After the json is edited, its type changes from object to string: can this be fixed too? |
See #71 |
Uhm, so I've translated via google translator but then I landed to this josdejong/svelte-jsoneditor#166 (comment) which is in English and better for me. So my fix in Vue 3 would be this one const updatedContent = (myupdate: any) => {
console.log("my update", myupdate);
myupdate.json = JSON.parse(myupdate.text);
myupdate.text = undefined
} and <JsonEditorVue v-else v-model="myJSON" :onChange="updatedContent" /> see my commit giuliohome-org/repro-jsoneditor-issue@2dbd3f6 Makes sense? |
I'm afraid there might be bugs in your code, as you have not considered other modes or edge cases. I recommend that you thoroughly read this: josdejong/svelte-jsoneditor#166 to get a better understanding. |
I mean... that it is restricted to my scenario, where I only use the text mode. Do you see possible bugs if the mode is always text and the menu is hidden? createApp(App)
.use(JsonEditorVue, {
"mode":"text", "mainMenuBar": false
}).mount('#app') Thanks |
Trust me, that's still buggy. I've mentioned that there are edge cases. I suggest reading josdejong/svelte-jsoneditor#166 thoroughly. You will understand what I'm talking about. |
Thanks, I understand, but the default behaviour is not usable for me in my code context. I have to call an API and I can't use a string as it is returned for sure. More or less this snippet should suffice for my use case. const updatedContent = (myupdate: any) => {
console.debug("textual update", myupdate);
if (myupdate.text !== "") {
try {
myupdate.json = JSON.parse(myupdate.text);
} catch {
console.debug("json is not valid: do nothing");
return;
}
} else {
myupdate.json = {};
}
myupdate.text = undefined;
console.debug("parsed update", myupdate.json);
} |
This is a very popular issue, and I have written the content below into the document: If you want to ensure you always get parsed JSON in text mode: Caution Not performant for large JSON documents. createApp(App)
.use(JsonEditorVue, {
mode: 'text',
mainMenuBar: false,
onChange(updatedContent) {
if (updatedContent.text) {
try {
updatedContent.json = JSON.parse(updatedContent.text)
}
catch {}
updatedContent.text = undefined
}
},
})
.mount('#app') or without <JsonEditorVue
ref="jsonEditorVueRef"
mode="text"
:main-menu-bar="false"
:on-change="(updatedContent) => {
if (updatedContent.text) {
if (!jsonEditorVueRef.jsonEditor.validate()) {
updatedContent.json = JSON.parse(updatedContent.text)
}
updatedContent.text = undefined
}
}"
/> |
Thank you @cloydlau for your reply ❣️ Will commit and try your suggestion asap on my project. Best regards |
Cool 🆒 as I like to define it at the main app level, because it allows me to reduce the proliferation of onChange functions for multiple JSON editor tags. However, I'm afraid I can't access the jsonEditorVueRef at that level. app.use(JsonEditorVue, {
mode: "text",
mainMenuBar: false,
onChange: (updatedContent: any) => {
if (updatedContent.text) {
try {
updatedContent.json = JSON.parse(updatedContent.text)
}
catch { }
updatedContent.text = undefined
}
}
}); |
It's possible with the ability of https://github.com/cloydlau/vue-global-config (another lib I created). But at the moment I don't see the necessity for it. |
@giuliohome Hello, in version 0.14.0 you can accomplish this in a more elegant way: Caution
<JsonEditorVue mode="text" :stringified="false" :debounce="1000" /> |
Thank you very much in advance! |
Will try soon. Meanwhile, a quick question in principle: While I don't think I have any performance issues, hence I will possibly reduce the debounce to 500 or even less, I'm wondering what it implies for a "save" button handler. Should it:
Correct? Thanks again! |
|
I know that. So, as a double check that my understanding is right, I'm saying that it implies that a click event handler should wait for the debounce interval time as well, before starting its action with the json value, do you agree? |
Certainly. Otherwise you might get dirty data. That's why I made it configurable. |
Excellent! Thank you for your help and support! |
Before you start, please make sure to:
Link to minimal (but complete) reproduction
https://github.com/giuliohome-org/repro-jsoneditor-issue/blob/main/src/components/HelloWorld.vue
Steps to reproduce
Main code
You see
![image](https://private-user-images.githubusercontent.com/3272563/321005567-35f34fb2-3031-4223-97a1-f9ed4a7b17b8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3Mi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ZTFNBNTNQUUs0WkElMkYyMDI0MDgwNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MDVUMDEwNDMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzZhYzU1ODUxZjI0MGNjNzhhNDI2OTVkZTZlNmE2YTFjMmE5NmEzZGUzODUxYjI5YWFjODJhMmY1MTk4MGRjMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.-Cew3jJDGdeFhJyNxlfHaJLZHUy3IXzhGlWIGJQyM4E)
If you click switchCondition
and then back to the previous json editor if you click again.
But now, if you edit a value
![image](https://private-user-images.githubusercontent.com/3272563/321006220-869c3ee1-e792-4dcc-9a98-027fa2ed1868.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI4MjAxNzMsIm5iZiI6MTcyMjgxOTg3MywicGF0aCI6Ii8zMjcyNTYzLzMyMTAwNjIyMC04NjljM2VlMS1lNzkyLTRkY2MtOWE5OC0wMjdmYTJlZDE4NjgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgwNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MDVUMDEwNDMzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzRmMTY3MTE4NGRhZGUwNWQzMjc4MGFiNDNiMTVhYjcyYWM1NzlkZjc0ZmE1MWNmODViYjhkMjFmNmVkNWM2NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.5ZOy0djViW1KnhMkqAzikznWulMNZBc7fnOWi8nUFnA)
for example
"a": 2
and you click 2 times again
the content visualization is ruined (and formatting does not work either)
What is expected?
Setting the v-if condition to false and back to true should not change the editor content visualization
What is actually happening?
A wrongly formatted text is displayed instead
System Info
Package Manager
npm
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: