I'm using React Rating (https://github.com/dreyescat/react-rating) and I'm not sure how to use get the value for my ratings. All of my other fields are working. I put in a console.log to see that their values have changed.
When I try to click on a star to rate the facility, I get the following error:
TypeError: undefined is not an object (evaluating 'event.target.name')
and it points to this line in my code:
formState[event.target.name] = event.target.value;
I know that I'm not targeting the Rating component correctly. I'm totally stumped. I haven't finished my button's onClick yet so I'm not worried about that.
Here is my code:
var Rating = require('react-rating')
class Assignment extends Component {
constructor(props) {
super(props)
this.state = {
form: {
site: '',
facilityRate: '',
theList: 'off'
}
}
}
handleChange(event) {
const formState = Object.assign({}, this.state.form);
formState[event.target.name] = event.target.value;
this.setState({ form: formState });
console.log(formState);
}
render() {
return (
<Grid>
<PageHeader id='header'>
Track your assignment <small className='subtitle'>Let us make a record of your assignment.</small>
</PageHeader>
<form id='assignment-form'>
<h3>Record your assignment</h3>
<Row>
<Col xs={5} md={5}>
<FormGroup>
<ControlLabel id='site'>Site Name</ControlLabel>
<FormControl type='text' name='site'
onChange={this.handleChange.bind(this)}
value={this.state.form.site}
/>
</FormGroup>
<FormGroup>
<ControlLabel id='facilityRate'>Rate the Facility
</ControlLabel><br />
<Rating
name='facilityRate'
emptySymbol={<img src='../star-empty.png' className='icon' alt='empty star' />}
fullSymbol={<img src='../star-full.png' className='icon' alt='filled star' />}
onChange={this.handleChange.bind(this)}
value={this.state.form.facilityRate} />
</FormGroup>
<FormGroup>
<ControlLabel id='theList'>The List
<br /><i>Add it to my favorites.</i>
</ControlLabel><br />
<Checkbox
name='theList'
checked={this.state.theList}
onChange={this.handleChange.bind(this)}>Add to The List
</Checkbox>
</FormGroup>
</Col>
</Row>
<Row>
<Col xs={5} md={5}>
<Button type='submit' className='btn btn-secondary' id='submit'>Submit Assignment</Button>
</Col>
</Row>
</form>
</Grid>
);
}
}