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

A way to disable some properties on build. #1480

Open
ebenshap opened this issue Jan 25, 2024 · 1 comment
Open

A way to disable some properties on build. #1480

ebenshap opened this issue Jan 25, 2024 · 1 comment
Labels

Comments

@ebenshap
Copy link

ebenshap commented Jan 25, 2024

General information

  • json-editor version: 2.11.0

Expected behavior

I'd like to be able to hide some editor properties when adding a new row. Right now all properties are included, unless the 'display_required_only' config is used at initialization. The problem with this solution is that I have to make properties that are not required in the business logic, required in the code, which creates a risky situation where if I initialize with an incomplete json object, then an error results.

Is there a way to set certain editor properties to be disabled in the Editor Options?

In the meantime I'm overwriting the code to disable certain editor properties with this code:

  const originalObjectSetValue = window.JSONEditor.defaults.editors.object.prototype.setValue
  window.JSONEditor.defaults.editors.object.prototype.setValue = function(value, initial) {
    originalObjectSetValue.call(this, value, initial)

    if(!initial) {
      return
    }
    // Disable some editors after build.
    if(this.addproperty_checkboxes['someEditor'] && this.addproperty_checkboxes['someEditor'].checked) {
      this.addproperty_checkboxes['someEditor'].click()
    }
  }

The actual logic I'm using checks to make sure I'm acting on the right object editor, but the idea is I'm altering the enabled properties with javascript events after the build. A better solution would be if this could be dealt with during the build, where some editor options config could be used by the build code to disable some editors directly. Please let me know if something like this already exists, or if there's a better way to achieve the desired result.

@schmunk42
Copy link
Collaborator

Do you want to disable an editor or set it as hidden?

Example with option hidden:

    "model": {
      "type": "string",
      "options": {
        "hidden": false
      }
    },

In general an example here https://pmk65.github.io/jedemov2/dist/demo.html would be helpful.

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

No branches or pull requests

2 participants