Skip to content
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

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

Closed
himalaya0035lumiq opened this issue Nov 30, 2023 · 5 comments
Closed
Labels
question Further information is requested

Comments

@himalaya0035lumiq
Copy link

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
Copy link
Owner

josdejong commented Nov 30, 2023

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

@josdejong josdejong added the question Further information is requested label Nov 30, 2023
@himalaya0035lumiq
Copy link
Author

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
Copy link
Author

himalaya0035lumiq commented Dec 1, 2023

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
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants