Code Monkey home page Code Monkey logo

Comments (5)

tedx avatar tedx commented on July 26, 2024

+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.

from json-editor.

jdorn avatar jdorn commented on July 26, 2024

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.

from json-editor.

SebT avatar SebT commented on July 26, 2024

+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.

from json-editor.

JogoShugh avatar JogoShugh commented on July 26, 2024

@SebT thank you so much!!!

from json-editor.

jdorn avatar jdorn commented on July 26, 2024

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.

from json-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.