json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

Send Raw JSON data #954

Closed ncrocfer closed 6 years ago

ncrocfer commented 6 years ago

Hello,

I'm trying to allow my users to send raw JSON in a field, using the CodeMirror extension (https://github.com/philippbosch/angular-schema-form-ui-codemirror).

Unfortunately the data is not validated as a valid JSON : codemirror_object

Here is my schema :

{
    'type': 'object',
    'additionalProperties': False,
    'properties': {
        'query': {
            'title': 'Your OpenTSDB query',
            'type': 'object',
            'description': 'Lorem ipsum...'
        }
    }
}

And my form :

{
    "key": "query",
    "type": "codemirror",
    "codemirrorOptions": {
          "lineNumbers": true,
          "mode": "javascript",
          "theme": "twilight"
    }
}

When I change the type for string type, the JS validation is ok but as I'm also using the schema in the Python backend, it's also failing :)

Thank you for your help, and thanks also for this great module !

Anthropic commented 6 years ago

I don't know that extension, have you contact the creator and asked for some input or a fix?

ncrocfer commented 6 years ago

Oups, no sorry I misspoke. The problem is not the extension, I have the same behaviour with a simple "textarea" type in the form definition.

I should not have talked about codemirror :)

My question is : how to send raw JSON data please ?

Anthropic commented 6 years ago

The easiest way would be to use an extension applied to a textarea that then updates the model. It wouldn't be hard to do, similar to writing a normal bit of code in angular only you turn it into a ccomponent, the framework is ultimately an angular template manager after all. If you take a look at the calculate extension in the example/add-on folder you can see how you can add whatever you like in a template and then add any required directives to it. If you want to start with the template used for a text area then you can manipulate it to do what you want it to.

ncrocfer commented 6 years ago

Ok great, I'll do it ! Thanks for your answer :)