jedemov2 icon indicating copy to clipboard operation
jedemov2 copied to clipboard

Req: Advanced Schema and JavaScript examples

Open pmk65 opened this issue 5 years ago • 6 comments

If anyone got a good Schema and/or JavaScript examples that show off some of the more advanced features of JSON-Editor, please post it here on the JSON-Editor Interactive Playground GitHub page.

I will then evaluate it and add it to the list of available examples. 🚀

pmk65 avatar Jun 09 '19 09:06 pmk65

I am posting this example of json-editor usage in case it is useful.

Example of jdorn/json-editor in action

Go to this robot-populated market simulation.

It won't bite. It runs completely in JS in your browser.

Click "Edit" to edit the simulation.

Look familiar? It should.

So that simulation editor is the old jdorn/json-editor code.

It also uses an extension json-editor-positive-number-array I wrote to make sure that buyers' unit values and sellers' unit costs are all positive numbers.

I am still using the json-editor in an improved simulator. It is easier than learning and dealing with react or some similar framework.

Extensions; Question

When entering an array of numbers, I find I need a wizard that would convert a formula to such a list.
For instance, the user might prefer "700-10j for j in [1,50]" or "700 690 ... 200" to "700 690 680 670 (etc)". I'm not asking you to do this for me, but I did find the old code a bit tricky to navigate. Hopefully my positive-number-array extension will still work with the rewrite and I can write something similar to that.

DrPaulBrewer avatar Jun 24 '19 00:06 DrPaulBrewer

@DrPaulBrewer Thanks for the example. I'll take a look at it (and your sddon) later. BTW: Wouldn't the positive number issue be solved without an extension, by setting the minimum property to 0 ?

pmk65 avatar Jun 24 '19 07:06 pmk65

I seem to recall (its been a while) that it may have been more about string parsing than about being strictly positive.

On Mon, Jun 24, 2019 at 3:26 AM Peter Klein [email protected] wrote:

@DrPaulBrewer https://github.com/DrPaulBrewer Thanks for the example. I'll take a look at it (and your sddon) later. BTW: Wouldn't the positive number issue be solved without an extension, by setting the minimum property to 0 ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pmk65/jedemov2/issues/22?email_source=notifications&email_token=AACRISFJBFKCPUWQ6K24FVDP4BZJVA5CNFSM4HWJCHM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYMAVRA#issuecomment-504892100, or mute the thread https://github.com/notifications/unsubscribe-auth/AACRISEZH5FZQGSREJOTTRDP4BZJVANCNFSM4HWJCHMQ .

DrPaulBrewer avatar Jun 24 '19 07:06 DrPaulBrewer

I seem to recall (its been a while) that it may have been more about string parsing than about being strictly positive.

I noticed that when I looked at the editor extension code. :)

I'm working on upgrading the Playground page, so that it can be used for complex setups. (Currently you can only add code AFTER JSON Editor have been initialized.) I think I finally figured out a way to do it by locking specific lines in the ACE editor. That way you will be able to add code BEFORE and AFTER the locked section)

As for your question, I put up a jsfiddle example here: https://jsfiddle.net/knq0sdxo/2/ It will parse comma separated positive numbers and ranges (string) into list (array) of single numbers. (duplicate numbers will be removed) i.e. 7,10,9-11 would return 7,9,10,11 Hope that will help you as a starting point. 😉

pmk65 avatar Jun 24 '19 16:06 pmk65

Thanks. The commas are not always helpful. Imagine you are in a hurry to enter a bunch of numbers, and it is only irritating if something rejects it. Thats why I try a few things in the extension I shared.

An optional [Sandbox] button in the UI right of the JSON/Properties buttons could provide a place for end users in technically-oriented apps to write a little Javascript code and have it execute in the context of the form object. A nice touch would be to do it with Function.prototype.apply() to set this to the JSON object being edited.

I intend to swap out the jdorn code for your code but It will be a while before I can come back to any of it as I am busy with some other phases of my robot trader project and also looking for some paid opportunities.

DrPaulBrewer avatar Jun 24 '19 23:06 DrPaulBrewer

I intend to swap out the jdorn code for your code but It will be a while before I can come back to any of it as I am busy with some other phases of my robot trader project and also looking for some paid opportunities.

The core code is pretty much the same, except a lot of bugs have been fixed. The updated version also contains a lot of extra editors, but they doesn't affect old setups.

Here's an updated version of the jsfiddle page, where you can set the delimiter to space (or any other character) https://jsfiddle.net/knq0sdxo/3/

pmk65 avatar Jun 25 '19 00:06 pmk65