brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
608 stars 168 forks source link

Remove empty values #24

Closed sgaynetdinov closed 4 years ago

sgaynetdinov commented 8 years ago

How to cancel the deletion?

idelvall commented 8 years ago

Sorry, I don't understand what you mean

sgaynetdinov commented 8 years ago

http://brutusin.org/json-forms/ schema

{
    "$schema": "http://json-schema.org/draft-03/schema#",
    "type": "object",
    "properties": {
        "a": {
            "title": "a",
            "type": "string"
        },
        "b": {
            "title": "b",
            "type": "string"
        }
    }
}

Initial data

{
  "a": "",
  "b": 1234
}
  1. click Create form
  2. click getData()
  3. result
{
    "b": "1234"
}

how to make that "a" key was not removed?

idelvall commented 8 years ago

I understand now. The problem is that HTML inputs don't have different states for null and empty values. I think we can add a working mode that let differentiate these states by letting the user toggle the inputs and move from these states: disabled (null) <-> enabled (empty) < -> enabled (non-empty). Do you feel capable of doing it?

sgaynetdinov commented 8 years ago

may return an empty string instead of the null?

https://github.com/brutusin/json-forms/blob/master/src/js/brutusin-json-forms.js#L673

return ""

https://github.com/brutusin/json-forms/blob/master/src/js/brutusin-json-forms.js#L938

return ""
idelvall commented 8 years ago

This could work for your case. I'll think about a more generic solution and keep you informed. Thanks!

sgaynetdinov commented 4 years ago

This error has already been fixed