Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No default value on nested field #1043

Closed
perusopersonale opened this issue Oct 5, 2018 · 3 comments
Closed

No default value on nested field #1043

perusopersonale opened this issue Oct 5, 2018 · 3 comments
Assignees

Comments

@perusopersonale
Copy link

perusopersonale commented Oct 5, 2018

Prerequisites

  • [ x ] I have read the documentation;
  • [ x ] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

I have a complex schema that is something like this:

{
 	"type": "object",
 	"properties": {
 		"type": {
 			"title": "Test",
 			"enum": ["foo", "bar"]
 		}
 	},
 	"dependencies": {
 		"type": {
 			"oneOf": [{
 					"properties": {
 						"type": {
 							"enum": ["foo"]
 						},
 						"algo_params": {
 							"$ref": "#/definitions/foo_params"
 						}
 					}
 				},
 				{
 					"properties": {
 						"type": {
 							"enum": ["bar"]
 						},
 						"algo_params": {
 							"$ref": "#/definitions/bar_params"
 						}
 					}
 				}
 			]
 		}
 	},
 	"additionalProperties": false,
 	"definitions": {
 		"foo_params": {
 			"type": "object",
 			"properties": {
 				"basic": {
 					"type": "object",
 					"properties": {
 						"test1": {
 							"type": "integer",
 							"default": 50,
 							"minimum": 1,
 							"maximum": 1000000
 						}
 					},
 					"additionalProperties": false,
 					"required": ["test1"]
 				},
 				"advanced": {
 					"type": "object",
 					"properties": {},
 					"additionalProperties": false
 				}
 			},
 			"additionalProperties": false,
 			"required": ["basic", "advanced"]
 		},
 		"bar_params": {
 			"type": "object",
 			"properties": {
 				"basic": {
 					"type": "object",
 					"properties": {
 						"test2": {
 							"type": "number",
 							"title": "",
 							"default": 0.1,
 							"minimum": 0,
 							"maximum": 1
 						}
 					},
 					"additionalProperties": false,
 					"required": ["test2"]
 				},
 				"advanced": {
 					"type": "object",
 					"properties": {
 						"test3": {
 							"type": "number",
 							"default": 1,
 							"minimum": 0,
 							"maximum": 1
 						}
 					},
 					"additionalProperties": false,
 					"required": ["test3"]
 				}
 			},
 			"additionalProperties": false,
 			"required": ["basic", "advanced"]
 		}
 	}
 }

When I use on Playground and select a type default values are correctly populated,
when I'm trying to use on my project default values are not shown.

Working example Playground

Test repo where default values are not shown:
https://jsfiddle.net/w1Lom0av/2

I'm not understanding why have different behavior.

Expected behavior

Default values shown. What I'm missing??

@perusopersonale
Copy link
Author

Ok if I handle onChange, update state, this rerender form and it works.
I think this should be the default behavior without the need to refresh form.

hatstand pushed a commit to hatstand/react-jsonschema-form that referenced this issue Nov 15, 2018
For dynamic dependencies, default properties were not being added.

There are two cases that were affected:
1. A dynamic dependency should be resolved based on a default.
2. Defaults from nested dynamic dependencies should be resolved.

Fixes rjsf-team#1043
@epicfaace
Copy link
Member

@perusopersonale -- the jsfiddle you sent is no longer working at all

@epicfaace epicfaace self-assigned this Jun 2, 2019
@epicfaace
Copy link
Member

Let me know if you have any other problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants