josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
816 stars 108 forks source link

Question: How to allow only certain fields of Json being editable ? #348

Closed himalaya0035lumiq closed 7 months ago

himalaya0035lumiq commented 7 months ago

Using vanilla-jsoneditor": "^0.19.0", for react Let's take this json for example { "name" : "sample", "age" : "22", "address" : { "city" : "sample city", "country" : "sample country" } }

For a certain reason, I only want age and "address.country" to be editable and not other fields when I double click on it. is there a way to achieve the same ?

Thanks

josdejong commented 7 months ago

There is currently no good way to do something like that. You can make specific fields read-only or customize how they are rendered using onRenderValue. But you can't really control it, since the user can work around it by renaming the key, then editing, and then renaming it again, or pasting content using Ctrl+V, or temporarily switch to text mode, or tricks like that.

It would be nice to have better control over this though, we could work out a plan for that.

Related: #342

himalaya0035lumiq commented 7 months ago

Thanks for your answer, Jos. I agree the user can work around by editing the key, changing the value then again renaming the key, but can't we disable the editing of keys altogether.

himalaya0035lumiq commented 7 months ago

and please tell me how to get rid of context Menu. Thanks

edit: I removed it using CSS, is there a prefered way ?

.jse-absolute-popup-content, .jse-context-menu-pointer-anchor, .jse-context-menu-pointer{
  display: none;
}
josdejong commented 7 months ago

There is no preferred way for this kind of customization :). Your CSS will indeed prevent the ContextMenu from opening (no guarantees though that this will keep working in the future).

himalaya0035lumiq commented 7 months ago

Thank you Jos and I disabled editing of keys by using pointer-events:none.