Exception when the root object is not an object
oscar-broman opened this issue · comments
Steps to reproduce
- Open the playground.
- Use a very simple schema (with empty UI and Rules):
{
"type": "number"
}
- Put a number in Data.
- Erase the number from the input field.
Outcome
The input field now contains [object Object]
.
The following errors are logged:
Warning: Failed prop type: Invalid prop `formData` supplied to `NumberField`.
in NumberField (created by SchemaField)
in SchemaField (created by Form)
in form (created by Form)
in Form (created by FormWithConditionals)
in FormWithConditionals (created by App)
in div (created by App)
in div (created by App)
in App (created by ResultForm)
in div (created by ResultForm)
in ResultForm (created by ResultForm)
in ResultForm
Warning: Failed prop type: Invalid prop `formData` supplied to `StringField`.
in StringField (created by NumberField)
in NumberField (created by SchemaField)
in div (created by DefaultTemplate)
in DefaultTemplate (created by SchemaField)
in SchemaField (created by Form)
in form (created by Form)
in Form (created by FormWithConditionals)
in FormWithConditionals (created by App)
in div (created by App)
in div (created by App)
in App (created by ResultForm)
in div (created by ResultForm)
in ResultForm (created by ResultForm)
in ResultForm
Warning: Failed prop type: Invalid prop `value` supplied to `TextWidget`.
in TextWidget (created by StatelessComponent)
in Unknown (created by StringField)
in StringField (created by NumberField)
in NumberField (created by SchemaField)
in div (created by DefaultTemplate)
in DefaultTemplate (created by SchemaField)
in SchemaField (created by Form)
in form (created by Form)
in Form (created by FormWithConditionals)
in FormWithConditionals (created by App)
in div (created by App)
in div (created by App)
in App (created by ResultForm)
in div (created by ResultForm)
in ResultForm (created by ResultForm)
in ResultForm
The problem is line 48:
https://github.com/RxNT/react-jsonschema-form-conditionals/blob/d1b45361226808810f788ab783d09b4682125555/src/runRules.js#L47-L67
Currently, it always defaults to {}
. Instead, the default value should depend on schema.type
. An empty string for all types except for objects. Not sure about arrays, though.
@oscar-broman thanks, I've fixed this, where you said. I've pushed fixed version to npm.