json-editor / json-editor

JSON Schema Based Editor
MIT License
4.49k stars 665 forks source link

defaultProperties doesn't work on live version #333

Open blacksages opened 5 years ago

blacksages commented 5 years ago

General information

"defaultProperties" attribute doesn't work.

It's expected for "name" property to be already present, but "name" property must be manually added in "properties tab"

Direct link to live example : https://json-editor.github.io/json-editor/?schema=N4IgLgngDgpiBcID2AjAVjAxmEAaEUATkrIWAJYwDOCoAdgIYC2c8oksCIVYh5dAcxABffAwGt20ViH5gYEwiNEgAJjABmDAK4AbMAAVipCtQQBtEIxYgAusKA==&value=N4XyA===&lib_switcher=&prompt_before_delete&upload=function(a,b,c){console.log(%22Upload%20handler%20required%20for%20upload%20editor%22)}&theme=bootstrap2&iconlib=fontawesome4&object_layout=normal&show_errors=interaction

or see example below :

{
  "type": "object",
  "properties": {
    "name": {"type": "string"},
    "age": {"type": "integer"}
  },
  "defaultProperties": ["name"]
}
schmunk42 commented 5 years ago

Works when "Object properties required by default" is used

https://json-editor.github.io/json-editor/?schema=N4IgLgngDgpiBcID2AjAVjAxmEAaEUATkrIWAJYwDOCoAdgIYC2c8oksCIVYh5dAcxABffAwGt20ViH5gYEwiNEgAJjABmDAK4AbMAAVipCtQQBtEIxYgAusKA==&value=N4IgdghgtgpiBcIQF8g=&lib_switcher=&prompt_before_delete&upload=function(a,b,c){console.log(%22Upload%20handler%20required%20for%20upload%20editor%22)}&theme=bootstrap2&iconlib=fontawesome4&object_layout=normal&show_errors=interaction&required_by_default

@pmk65 Is this intended? It sounds somehow confusing to me.

pmk65 commented 5 years ago

@pmk65 Is this intended? It sounds somehow confusing to me.

Hard to tell, the documentation isn't very informative about the defaultProperties property. and in the code there isn't much info either. 😕 It's a JSON-Editor special feature. https://github.com/jdorn/json-editor/issues/220 But it seem to have some issues according to the old repo.

pmadril commented 5 years ago

Work as intended on old JDorn version:

http://jeremydorn.com/json-editor/?schema=N4IgLgngDgpiBcID2AjAVjAxmEAaEUATkrIWAJYwDOCoAdgIYC2c8oksCIVYh5dAcxABffAwGt20ViH5gYEwiNEgAJjABmDAK4AbMAAVipCtQQBtEIxYgAusKAA=&value=N4IgdghgtgpiBcIQF8gAAA==&theme=bootstrap2&iconlib=fontawesome4&object_layout=normal&show_errors=interaction

and on Interactive Playground (even with required by default: false):

https://is.gd/Vbctcv

but not on Interactive demo:

https://json-editor.github.io/json-editor/?schema=N4IgLgngDgpiBcID2AjAVjAxmEAaEUATkrIWAJYwDOCoAdgIYC2c8oksCIVYh5dAcxABffAwGt20ViH5gYEwiNEgAJjABmDAK4AbMAAVipCtQQBtEIxYgAusKA==&value=N4XyA===&lib_switcher=&prompt_before_delete&upload=function(a,b,c){console.log(%22Upload%20handler%20required%20for%20upload%20editor%22)}&theme=bootstrap2&iconlib=fontawesome4&object_layout=normal&show_errors=interaction

Useful when you want some properties required and some optional but shown (on Playground, which seems to be ok):

https://is.gd/IMTyVF

faoFurkanMacit commented 10 months ago

Is there anyone having the same issue ? I am not able to make defaultProperties work properly

pmadril commented 7 months ago

Test schema: { "type": "object", "properties": { "name": {"type": "string"}, "surname": {"type": "string"}, "age": {"type": "integer"} }, "defaultProperties": ["name", "surname"], "required": ["name"] }

My understanding:

In both demos (interactive and playground), seems to be OK. Setting "required by default" option does not give a valid JSON until "age" (and name and surname) is filled with a value.

@faoFurkanMacit can you please post the use case that shows the issue?

Thank you, and sorry for my English