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

implementing callbacks for onChangeJSON is problematic... #52

Open
TroyLDay opened this issue Aug 21, 2019 · 6 comments
Open

implementing callbacks for onChangeJSON is problematic... #52

TroyLDay opened this issue Aug 21, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@TroyLDay
Copy link

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",
@mariohmol
Copy link
Owner

Hi!

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

@mariohmol mariohmol added the enhancement New feature or request label Sep 4, 2019
@mariohmol
Copy link
Owner

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

@osmanraifgunes
Copy link
Contributor

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

@mariohmol
Copy link
Owner

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

@osmanraifgunes
Copy link
Contributor

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

@mariohmol
Copy link
Owner

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

and here

this.jsonChange.emit(this.editor.get());

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?

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

No branches or pull requests

3 participants