Parcourir la source

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 il y a 9 ans
Parent
commit
31b8fb130f

+ 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"