Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined is not a function (evaluating 'this.validate') #1

Open
ridhofh opened this issue Jun 16, 2017 · 11 comments
Open

Undefined is not a function (evaluating 'this.validate') #1

ridhofh opened this issue Jun 16, 2017 · 11 comments

Comments

@ridhofh
Copy link

ridhofh commented Jun 16, 2017

I got error in _onPressButton, it refers to :
_onPressButton() {
// Call ValidationComponent validate method
this.validate({
userEmail: {email: true, minlength:6, required: true},
userPassword: {minlength:6, required: true}
}).then(Actions.index());
}

@perscrew
Copy link
Owner

Hi @ridhofh ! The validate methods doesn't return a promise. This is synchronous operation.

@ridhofh
Copy link
Author

ridhofh commented Jun 16, 2017

so, what must i do, to run validate function from ValidationComponent?

@perscrew
Copy link
Owner

Sorry for the delay, you just have to extend ValidationComponent to your custom React Component and call : this.validate() in your click handler.

The validate methods will populate some validation informations in the root of your component.

@stephenfromrobin
Copy link

I'm having this issue too. Could you provide some sample code?

@thg303
Copy link
Contributor

thg303 commented Sep 13, 2017

see the documentation:

import ValidationComponent from 'react-native-form-validator';
 
export default class MyForm extends ValidationComponent {
  ...
}

@ArsooCh
Copy link

ArsooCh commented Jan 27, 2018

getting the same error
Undefined is not a function (evaluating 'this.validate')

@ghost
Copy link

ghost commented May 21, 2018

import React, { Component } from 'react';
import { View, Text, TextInput, TouchableHighlight } from 'react-native';
import ValidationComponent from '../../validator/index';

export default class App extends ValidationComponent {

constructor(props) {
super(props);
// this.state = {name : "My name", email: "tibtib@gmail.com", number:"56", date: "2017-03-01"};
this.state = { name: "", email: "", number: "", date: "" };
}

_onPressButton = () => {
this._validateForm();
};
onChangeTextName = (text) => {
this.setState({ name: text });
this.validate({
name: { minlength: 3, maxlength: 7, required: true }
});

}
onChangeTextEmail = (text) => {
this.setState({ email: text });
this.validate({
email: { email: true }
});

}
onChangeTextDigit = (text) => {
this.setState({ number: text });
this.validate({
number: { numbers: true }
});

}
onChangeTextDate = (text) => {
this.setState({ date: text });
this.validate({
date: { date: 'YYYY-MM-DD' }
});

}

_validateForm() {
this.validate({
name: { minlength: 3, maxlength: 7, required: true },
email: { email: true },
number: { numbers: true },
date: { date: 'YYYY-MM-DD' }
});
}

render() {

return (
  <View style={{ paddingVertical: 30 }}>
    <Text>Name</Text>
    <TextInput ref="name" onChangeText={(name) => this.onChangeTextName(name)} value={this.state.name} />
    <Text>{(this.isFieldInError('name') && this.getErrorsInField('name'))?this.getErrorsInField('name'):''}</Text>

    <Text>Email</Text>
    <TextInput ref="email" onChangeText={(email) => this.onChangeTextEmail(email)} value={this.state.email} />
    <Text>{(this.isFieldInError('email') && this.getErrorsInField('email'))?this.getErrorsInField('email'):''}</Text>
    <Text>Number</Text>
    <TextInput ref="number" onChangeText={(number) => this.onChangeTextDigit(number)} value={this.state.number} />
    <Text>{(this.isFieldInError('number') && this.getErrorsInField('number'))?this.getErrorsInField('number'):''}</Text>
    <Text>DoB</Text>
    <TextInput ref="date" onChangeText={(date) => this.onChangeTextDate(date)} value={this.state.date} />
    <Text>{(this.isFieldInError('date') && this.getErrorsInField('date'))?this.getErrorsInField('date'):''}</Text>
   
    <TouchableHighlight onPress={this._onPressButton}>
      <Text>Submit</Text>
    </TouchableHighlight>

    
  </View>
);

}

}

@ghost
Copy link

ghost commented May 21, 2018

Use this
_onPressButton = () => {
this.validate({
name: { minlength: 3, maxlength: 7, required: true },
email: { email: true },
number: { numbers: true },
date: { date: 'YYYY-MM-DD' }
});
}

Instead of
_onPressButton(){
this.validate({
name: { minlength: 3, maxlength: 7, required: true },
email: { email: true },
number: { numbers: true },
date: { date: 'YYYY-MM-DD' }
});
}

@DheereshSinghKarki
Copy link

after using arrow function too it gives same error

@callyrajiv
Copy link

callyrajiv commented Dec 2, 2019

@DheereshSinghKarki

You have to use 'bind' :

<TouchableHighlight onPress={this._onPressButton.bind(this)}> <Text>Submit</Text> </TouchableHighlight>

@naveenjothi
Copy link

thank you@DheereshSinghKarki its working for me

perscrew pushed a commit that referenced this issue Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants