fix bug introduced in value change code

This commit is contained in:
Rick Watson 2019-08-09 21:26:31 +01:00
parent 391fe85a4b
commit cf48c79b4d
2 changed files with 12 additions and 5 deletions

View File

@ -89,7 +89,13 @@ export const restComponent = (endpointUrl, FormComponent) => {
}); });
} }
handleValueChange = name => (event, newValue) => { handleValueChange = name => (event) => {
const { data } = this.state;
data[name] = event.target.value;
this.setState({ data });
};
handleSliderChange = name => (event, newValue) => {
const { data } = this.state; const { data } = this.state;
data[name] = newValue; data[name] = newValue;
this.setState({ data }); this.setState({ data });
@ -105,6 +111,7 @@ export const restComponent = (endpointUrl, FormComponent) => {
return <FormComponent return <FormComponent
handleValueChange={this.handleValueChange} handleValueChange={this.handleValueChange}
handleCheckboxChange={this.handleCheckboxChange} handleCheckboxChange={this.handleCheckboxChange}
handleSliderChange={this.handleSliderChange}
setData={this.setData} setData={this.setData}
saveData={this.saveData} saveData={this.saveData}
loadData={this.loadData} loadData={this.loadData}

View File

@ -21,7 +21,7 @@ class DemoController extends Component {
} }
render() { render() {
const { data, fetched, errorMessage, saveData, loadData, handleValueChange } = this.props; const { data, fetched, errorMessage, saveData, loadData, handleSliderChange } = this.props;
return ( return (
<SectionContent title="Controller" titleGutter> <SectionContent title="Controller" titleGutter>
<LoadingNotification <LoadingNotification
@ -33,7 +33,7 @@ class DemoController extends Component {
demoSettings={data} demoSettings={data}
onReset={loadData} onReset={loadData}
onSubmit={saveData} onSubmit={saveData}
handleValueChange={handleValueChange} handleSliderChange={handleSliderChange}
/> />
} }
/> />
@ -53,7 +53,7 @@ const useStyles = makeStyles(theme => ({
})); }));
function DemoControllerForm(props) { function DemoControllerForm(props) {
const { demoSettings, onSubmit, onReset, handleValueChange } = props; const { demoSettings, onSubmit, onReset, handleSliderChange } = props;
const classes = useStyles(); const classes = useStyles();
return ( return (
<ValidatorForm onSubmit={onSubmit}> <ValidatorForm onSubmit={onSubmit}>
@ -67,7 +67,7 @@ function DemoControllerForm(props) {
valueLabelDisplay="on" valueLabelDisplay="on"
min={0} min={0}
max={255} max={255}
onChange={handleValueChange('blink_speed')} onChange={handleSliderChange('blink_speed')}
/> />
<Button variant="contained" color="primary" className={classes.button} type="submit"> <Button variant="contained" color="primary" className={classes.button} type="submit">
Save Save