Handle on change in field

This commit is contained in:
lukasmartinelli 2016-09-12 20:29:53 +02:00
parent 7c7c8b7111
commit ae0a12dcd8
5 changed files with 25 additions and 8 deletions

View file

@ -11,9 +11,13 @@ static propTypes = {
doc: React.PropTypes.string,
}
onChange(e) {
return this.props.onChange(e.target.value)
}
render() {
return <Input
onChange={this.props.onChange}
onChange={this.onChange.bind(this)}
label={this.props.name}
name={this.props.name}
value={this.props.value}

View file

@ -10,12 +10,16 @@ class EnumField extends React.Component {
doc: React.PropTypes.string,
}
onChange(e) {
return this.props.onChange(e.target.value)
}
render() {
const options = this.props.allowedValues.map(val => {
return {children: val, value: val}
})
return <Select
onChange={this.props.onChange}
onChange={this.onChange.bind(this)}
name={this.props.name}
options={options}
label={this.props.name}

View file

@ -14,9 +14,14 @@ class NumberField extends React.Component {
doc: React.PropTypes.string,
}
onChange(e) {
return this.props.onChange(parseFloat(e.target.value))
}
render() {
return <Input type="number"
onChange={this.props.onChange}
return <Input
type="number"
onChange={this.onChange.bind(this)}
label={this.props.name}
name={this.props.name}
message={this.props.doc}

View file

@ -18,8 +18,8 @@ class SpecField extends React.Component {
]).isRequired,
}
onValueChanged(property, e) {
return this.props.onChange(property, e.target.value)
onValueChanged(property, value) {
return this.props.onChange(property, value)
}
render() {

View file

@ -6,14 +6,18 @@ class StringField extends React.Component {
static propTypes = {
onChange: React.PropTypes.func.isRequired,
name: React.PropTypes.string.isRequired,
value: React.PropTypes.number,
value: React.PropTypes.string,
default: React.PropTypes.number,
doc: React.PropTypes.string,
}
onChange(e) {
return this.props.onChange(e.target.value)
}
render() {
return <Input
onChange={this.props.onChange}
onChange={this.onChange.bind(this)}
label={this.props.name}
name={this.props.name}
value={this.props.value}