Просмотр исходного кода

Fix Switch components not getting set with the default value the first time they render

Add support for 'string' boolean values in case the server sends the default boolean values as string.
Sergiu Miclea 8 лет назад
Родитель
Сommit
31b8fb130f
2 измененных файлов с 6 добавлено и 1 удалено
  1. 4 0
      src/components/Switch/Switch.js
  2. 2 1
      src/components/WizardOptions/WizardOptions.js

+ 4 - 0
src/components/Switch/Switch.js

@@ -37,6 +37,10 @@ class Switch extends Component {
     }
   }
 
+  componentWillReceiveProps(newProps) {
+    this.setState({ checked: newProps.checked })
+  }
+
   handleChange(e) {
     if (this.props.onChange) {
       this.props.onChange(e)

+ 2 - 1
src/components/WizardOptions/WizardOptions.js

@@ -203,7 +203,8 @@ class WizardOptions extends Reflux.Component {
               <InfoIcon text={Helper.getCloudFieldDescription(field.name)} />
             </div>
             <Switch
-              checked={this.state.destination_environment[field.name] === true}
+              checked={this.state.destination_environment[field.name] === true ||
+                this.state.destination_environment[field.name] === 'true'}
               onChange={(e) => this.handleOptionsFieldChange(e, field)}
               checkedLabel="Yes"
               uncheckedLabel="No"