Juicy / juicy-jsoneditor

Polymer Element that wraps josdejong/jsoneditor and adds two-way binding for edited JSON.
http://juicy.github.io/juicy-jsoneditor/
MIT License
42 stars 12 forks source link

json editor set schema #9

Open mbana opened 8 years ago

mbana commented 8 years ago

Can you please post a working example of getting access to the actual editor field? I'd like to set a schema on it. I can't see how it is exposed, nor events being fired when it is initialised.

Many thanks for the lib. Good work.


Edit: modes='["code", "form", "text", "tree", "view"]' is the new syntax in Polymer. The examples use: modes="['code', 'form', 'text', 'tree', 'view']".

tomalec commented 8 years ago

Thanks for the feedback! :)

Regarding the access to the editor itself, once element is attached to your DOM, you should be able to do just:

var aceEditorInstance = document.querySelector('juicy-jsoneditor').editor;

then you can perform anything josdejong/jsoneditor API allows.

Is that what you want, or do need to access just the input field?

mbana commented 7 years ago

I was hoping I would bind to the editor field directly. Any reason why we can't have, either or both:

  1. push the editor to the property so parent can bind to it.
  2. fire an event when ready.

The first requires less code. Second is equally acceptable.

An aside:

1. <link rel="import" href="../polymer/polymer.html">

Do you mind changing that to to something like: http://stackoverflow.com/a/31484427, i.e., base href support.

tomalec commented 7 years ago

Regarding:

  1. editor is already a property. Do you mean you would like to make it Polymer-observable property? I'm a little bit afraid of performance cost, of putting live JSON Editor (+ACE Editor) object into Polymer notification protocol, which is known to be prone to bugs.

    It would be great if you could provide your use case as a code sample, so I could get better understanding of your needs.

  2. Great idea, I have created a separate issue for that https://github.com/Juicy/juicy-jsoneditor/issues/10 (PRs welcome ;) )

Regarding aside: I would rather avoid such change. <link rel="import" href="../polymer/polymer.html"> is common practice across Polymer and Vanilla Custom Elements - conventional path make it also easier to handle de-duplication of dependencies. Moreover, we do use <juicy-jsoneditor> on production, and RawGit as a free service gives no uptime guarantees.