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

Documentation/Tutorial for Creating a Custom Editor #6

Open
jdorn opened this issue Dec 1, 2013 · 5 comments
Open

Documentation/Tutorial for Creating a Custom Editor #6

jdorn opened this issue Dec 1, 2013 · 5 comments

Comments

@jdorn
Copy link
Owner

jdorn commented Dec 1, 2013

No description provided.

@tedx
Copy link

tedx commented Jun 15, 2014

+1
I like the concept and I'd like to take a shot at a custom editor but I could use a tutorial or better documentation.

@jdorn
Copy link
Owner Author

jdorn commented Jun 16, 2014

I've started filling out the wiki (https://github.com/jdorn/json-editor/wiki) with more in-depth documentation. I haven't documented custom editors yet, but the notes on overall code structure may still be helpful.

@SebT
Copy link
Contributor

SebT commented Jun 20, 2014

+1
I have a pretty annoying problem with a (simple) custom editor. It doesn't work great with validate and getValue on the global form object.

I update the this.value variable of the editor correctly (use console.log to make sure) when the user fills the form, yet when I use one of the two functions mentioned above, the value for the editor is null or undefined.
BUT if the users changes another value on the form that uses a default editor, the next getValueor validate call will return the right value for my custom editor.

I have noticed in default editors code that you often use this portion of code:

this.jsoneditor.notifyWatchers(this.path);
if(this.parent) this.parent.onChildEditorChange(this);
else this.jsoneditor.onChange();

So I tried it and it worked. The problem is that if my schema has an array with the items schema set to a custom editor, it generates an error on the editor of the first item of the table, whereas there is no first item.

I don't know if I explained my problem correctly, but my final question is:

[TL:DR] How to update a custom editor's value correctly ?

Edit: I replaced the problematic code above with

if(this.jsoneditor) {
  this.jsoneditor.notifyWatchers(this.path);
  if(this.parent) this.parent.onChildEditorChange(this);
  else this.jsoneditor.onChange();
}

and it seems to work fine now.

@JogoShugh
Copy link

@SebT thank you so much!!!

@jdorn
Copy link
Owner Author

jdorn commented Feb 28, 2015

I started documenting the editor class in the wiki - https://github.com/jdorn/json-editor/wiki#editor-srceditorjs

The solution @SebT has is slightly out of date. It should be replaced with just this.onChange(true). I recommend reading through the wiki which goes through the major editor methods and what is supposed to happen in each.

flibbertigibbet added a commit to flibbertigibbet/json-editor that referenced this issue Oct 30, 2015
…selector-reset

Prevent dynamic select values being changed on initial load.
PhE pushed a commit to PhE/json-editor that referenced this issue May 21, 2018
* LV: Moved examples -> docs

* LV: Moved demo -> docs. Pulling JS from unpkg vs dist folder (dist eventually doesn't really need to be in github)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants