Quellcode durchsuchen

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 vor 8 Jahren
Ursprung
Commit
31b8fb130f
2 geänderte Dateien mit 6 neuen und 1 gelöschten Zeilen
  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) {
   handleChange(e) {
     if (this.props.onChange) {
     if (this.props.onChange) {
       this.props.onChange(e)
       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)} />
               <InfoIcon text={Helper.getCloudFieldDescription(field.name)} />
             </div>
             </div>
             <Switch
             <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)}
               onChange={(e) => this.handleOptionsFieldChange(e, field)}
               checkedLabel="Yes"
               checkedLabel="Yes"
               uncheckedLabel="No"
               uncheckedLabel="No"