fix(try-it-out): required boolean default value set to empty string (#6449)

ref: #6429

* fix(try-it-out): required boolean default value set to empty string
* test(try-it-out): required enum and boolean fields
This commit is contained in:
Tim Lai
2020-09-30 15:27:41 -07:00
committed by GitHub
parent ad630cc3e0
commit f5c709f97f
3 changed files with 220 additions and 6 deletions

View File

@@ -320,18 +320,16 @@ export class JsonSchema_boolean extends Component {
let { getComponent, value, errors, schema, required, disabled } = this.props
errors = errors.toJS ? errors.toJS() : []
let enumValue = schema && schema.get ? schema.get("enum") : null
if (!enumValue) {
// in case schema.get() also returns undefined/null
enumValue = fromJS(["true", "false"])
}
let allowEmptyValue = !enumValue || !required
let booleanValue = !enumValue && fromJS(["true", "false"])
const Select = getComponent("Select")
return (<Select className={ errors.length ? "invalid" : ""}
title={ errors.length ? errors : ""}
value={ String(value) }
disabled={ disabled }
allowedValues={ enumValue }
allowEmptyValue={ !required }
allowedValues={ enumValue || booleanValue }
allowEmptyValue={ allowEmptyValue }
onChange={ this.onEnumChange }/>)
}
}