So I am trying to populate the dropdown with some info from another table using props. Currently have this. I had to do the loop backwards because earlier it was breaking,
import React, { Component, PropTypes } from 'react';
import {
Button,
ControlLabel,
FormGroup,
Form,
FormControl
} from 'react-bootstrap';
class UserForm extends Component {
constructor(props) {
super(props);
}
createPosItems() {
const posItems = [];
console.log('heyyyy', this.props);
for (let i = this.props.position.length; i > this.props.position.length; i--) {
posItems.push(<option key={i} value={this.props.position.i}>{this.props.position.position_name}</option>);
}
return posItems;
}
createTeamItems() {
const teamItems = [];
console.log('whyyyyy', this.props);
for (let i = this.props.team.length; i > this.props.team.length; i--) {
teamItems.push(<option key={i} value={this.props.team.i}>{this.props.team.team_name}</option>);
}
return teamItems;
}
render() {
return (
<div className="row">
<div className="col-lg-12">
<Form>
<FormGroup controlId="employeeFirstName">
<ControlLabel>First Name</ControlLabel>
<FormControl
type="text"
name="firstName"
required=""
value={this.props.user.firstName}
onChange={this.props.onChange}
/>
</FormGroup>
<FormGroup controlId="empEmail">
<ControlLabel>Email</ControlLabel>
<FormControl
type="email"
name="email"
required=""
value={this.props.user.email}
onChange={this.props.onChange}
/>
</FormGroup>
<FormGroup controlId="position">
<ControlLabel>Job Position</ControlLabel>
<FormControl
componentClass="select"
>
<option value="">Select a Position</option>
{this.createPosItems()}
</FormControl>
</FormGroup>
<FormGroup controlId="Team">
<ControlLabel>Team</ControlLabel>
<FormControl
componentClass="select"
>
<option value="">Select a Team</option>
{this.createTeamItems()}
</FormControl>
</FormGroup>
<FormGroup>
<Button
pullRight
type="submit"
className="btn btn-success"
disabled={this.props.saving}
onClick={this.props.onSave}
>Save</Button>
<Button
pullRight
type="submit"
className="btn btn-danger pull-right"
// onClick={this.props.onDelete}
>Delete</Button>
</FormGroup>
</Form>
</div>
</div>
);
}
}
UserForm.propTypes = {
user: React.PropTypes.object.isRequired,
team: React.PropTypes.array.isRequired,
position: React.PropTypes.array.isRequired,
onSave: React.PropTypes.func.isRequired,
onChange: React.PropTypes.func.isRequired,
saving: React.PropTypes.bool
};
export default UserForm;
The forms is a child of another page. Every other field works, expect for the drop downs, the element shows up, but doesn't populate the drop down. Have tried using multiple people's examples, and still cannot get it to run. Thanks in advance!