Skip to content

Commit 19de8fb

Browse files
authored
Merge pull request #287 from MetaCell/feature/247_conn_weight_float_func
#247 Handle float input in case of func type field
2 parents 42df22c + a076140 commit 19de8fb

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

webapp/components/general/PythonControlledCapability.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ define((require) => {
9393
});
9494

9595
// If a handleChange method is passed as a props it will overwrite the handleChange python controlled capability
96-
this.handleChange = (this.props.handleChange == undefined) ? this.handleChange.bind(this) : this.props.handleChange.bind(this);
96+
this.handleChange = (this.props.handleChange === undefined) ? this.handleChange.bind(this) : this.props.handleChange.bind(this);
9797
this.handleUpdateInput = this.handleUpdateInput.bind(this);
9898
this.handleUpdateCheckbox = this.handleUpdateCheckbox.bind(this);
9999
}
@@ -121,7 +121,7 @@ define((require) => {
121121
}
122122
}, timeInterval);
123123
} else {
124-
console.warn(`Tried to sync default value for ${this.props.model} and failed after 3 attemps.`);
124+
console.warn(`Tried to sync default value for ${this.props.model} and failed after 3 attempts.`);
125125
}
126126
}
127127

@@ -188,9 +188,9 @@ define((require) => {
188188
if (this.props.prePythonSyncProcessing !== undefined) {
189189
newValue = this.props.prePythonSyncProcessing(newValue);
190190
}
191-
// whenever we invoke syncValueWithPython we will propagate the Javascript value of the model to Python
191+
// whenever we invoke syncValueWithPython we will propagate
192+
// the Javascript value of the model to Python
192193
if (this.syncValueWithPython) {
193-
// this.syncValueWithPython((event.target.type == 'number') ? parseFloat(this.state.value) : this.state.value, this.props.requirement);
194194
switch (this.props.realType) {
195195
case 'float':
196196
if (!isNaN(newValue) && newValue !== '') {
@@ -202,6 +202,13 @@ define((require) => {
202202
newValue = JSON.parse(newValue);
203203
}
204204
break;
205+
case 'func':
206+
// 'func' type can be a function or a float in netpyne
207+
// In case the value is a float we want to convert "1.4" -> 1.4
208+
if (!isNaN(newValue) && newValue !== '') {
209+
newValue = parseFloat(newValue);
210+
}
211+
break;
205212
default:
206213
break;
207214
}
@@ -354,16 +361,6 @@ define((require) => {
354361
this.callPythonMethod();
355362
}
356363

357-
/*
358-
* TODO: this function appears defined 2 times
359-
* I think the last def is picked up, so I am commenting this one
360-
* componentDidUpdate (prevProps, prevState) {
361-
* if (this.state.value != prevState.value && this.props.onChange) {
362-
* this.props.onChange(null, null, this.state.value);
363-
* }
364-
* }
365-
*/
366-
367364
updatePythonValue (newValue) {
368365
this.setState({
369366
value: newValue,

0 commit comments

Comments
 (0)