Hi,
please add es6 class support for the getValue().
When I define a new component as a class, I can't use the this.ref.form.getValue() function to get
the values.
Example class:
class CreateEvent extends React.Component {
componentDidMount() {
//this.refs.form.getComponent('menu').refs.input.focus();
}
onPress() {
console.log('Save button pressed.')
// call getValue() to get the values of the form
var value = this.refs.form.getValue();
if (value) { // if validation fails, value will be null
console.log(value); // value here is an instance of Person
}
}
render() {
return (
<ScrollView
horizontal={false}
contentInset={{top: -50}}
style={[Styles.scrollView, Styles.horizontalScrollView]}>
<View style={Styles.container}>
<Form
ref="form"
type={Person}
options={options}
/>
<TouchableHighlight style={Styles.button} onPress={this.onPress} underlayColor='#99d9f4'>
<Text style={Styles.buttonText}>Save</Text>
</TouchableHighlight>
</View>
</ScrollView>
);
}
}
Error:
javascript
Error: Cannot read property 'form' of undefined
stack:
Object.CreateEvent.onPress index.ios.bundle:55308
React.createClass.touchableHandlePress index.ios.bundle:34825
TouchableMixin._performSideEffectsForTransition index.ios.bundle:33004
TouchableMixin._receiveSignal index.ios.bundle:32928
TouchableMixin.touchableHandleResponderRelease index.ios.bundle:32731
executeDispatch index.ios.bundle:12786
forEachEventDispatch index.ios.bundle:12774
Object.executeDispatchesInOrder index.ios.bundle:12795
executeDispatchesAndRelease index.ios.bundle:12174
URL: undefined
line: undefined
message: Cannot read property 'form' of undefined```
<TouchableHighlight style={Styles.button} onPress={this.onPress.bind(this)} underlayColor='#99d9f4'>
bind(this) is missing
Ok, thanks!
Maybe it's worth a note in the docs for noobs like me ;-)
make it as arrow function fix the problems
onPress = () => {
console.log('Save button pressed.')
// call getValue() to get the values of the form
var value = this.refs.form.getValue();
if (value) { // if validation fails, value will be null
console.log(value); // value here is an instance of Person
}
}
Most helpful comment
bind(this)is missing