ang-jsoneditor icon indicating copy to clipboard operation
ang-jsoneditor copied to clipboard

implementing callbacks for onChangeJSON is problematic...

Open TroyLDay opened this issue 5 years ago • 6 comments

Describe the bug I've implemented the editor with the angular wrapper, and have specified functions for onChange and onChangeJSON. onChange can be bound within the template, whereas onChangeJSON cannot, so I've added it to the editorOptions object.

this.editorOptions = new JsonEditorOptions();
this.editorOptions.mode = 'tree';
this.editorOptions.onChangeJSON = this.onEditorChangeJSON.bind(this);

At runtime, the value provided in the onChangeJSON callback is the entire json object, rather than the more fine grained values suggested by the documentation. What's more, the closure context of the function is the options object, rather than the component. I've addressed that by defining the options object like so:

This results in a somewhat odd way to access the editor in the callback:

onEditorChangeJSON(json) {
    const json2 = this.editor.editor.get(); // notice how the editor is now a private member of the component reference.
}

Also, the get method returns the entire json, rather than the finer grained value that had changed.

Expected behavior onChangeJSON should behave as suggested in the json-editor documentation: "Set a callback function triggered when the contents of the JSONEditor change. Passes the changed contents as a JSON object."

Is this a bug, an implementation issue, or something else?

Console and Error stack trace No error.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome "@angular/core": "~8.2.2", "ang-jsoneditor": "^1.8.2", "jsoneditor": "^6.2.1",

TroyLDay avatar Aug 21 '19 15:08 TroyLDay

Hi!

Thanks for that.. i'm just kind lost about what is your suggestion.. what should we do here?

mariohmol avatar Sep 04 '19 00:09 mariohmol

Hi @osmanraifgunes , can u tell me if #58 fixes this?

mariohmol avatar Feb 08 '20 01:02 mariohmol

No it does not.I solved this problem by editing original jsoneditor. But it is a temporary solution.

osmanraifgunes avatar Feb 11 '20 08:02 osmanraifgunes

did u open an issue on jsoneditor repo? if u can link it here..

mariohmol avatar Feb 11 '20 13:02 mariohmol

No I did not open. In fact it is not their bug. I just wangled that component. Problem is in ang-jsoneditor component.

osmanraifgunes avatar Feb 11 '20 13:02 osmanraifgunes

Well.. as we can see here https://github.com/josdejong/jsoneditor/blob/9e9fd72eddafe9c8da88be032571e10c860220e9/src/js/previewmode.js#L333

and here

https://github.com/mariohmol/ang-jsoneditor/blob/22ef5fc9121e57f5964db6f578aee7b1e617fe9b/ang-jsoneditor/src/jsoneditor/jsoneditor.component.ts#L128

They act as the same as the original repo.. to be honest I dont see this expected behaviour at the original repo...

Am I missing something?

mariohmol avatar Feb 11 '20 13:02 mariohmol