Skip to content

Commit

Permalink
fixes #195 add setDefault to populate default value from the Select c…
Browse files Browse the repository at this point in the history
…onstructor
  • Loading branch information
stevehu committed Apr 24, 2020
1 parent 5e08681 commit 5e845cd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
onChangeValidate: any,
localization: Localization,
onChange: any,
setDefault: any,
error: any
};

Expand All @@ -25,7 +26,12 @@ type State = {
class Select extends Component<Props, State> {
constructor(props) {
super(props);
const { model, form } = this.props;
const {
model,
form,
setDefault,
form: { key }
} = this.props;

let defaultValue =
form && form.selectProps && form.selectProps.multiple ? [] : "";
Expand All @@ -34,10 +40,12 @@ class Select extends Component<Props, State> {
} else if (props.form.schema && props.form.schema.default) {
defaultValue = props.form.schema.default;
}
const currentValue =
utils.getValueFromModel(model, form.key) || defaultValue;
this.state = {
currentValue:
utils.getValueFromModel(model, form.key) || defaultValue
currentValue
};
setDefault(key, model, form, currentValue);
}

onSelected = event => {
Expand Down

0 comments on commit 5e845cd

Please sign in to comment.