Friday, March 1, 2019

React Native Validation

import React, { Component } from 'react'
import { TextInput, Button, View, Text } from 'react-native'


class Home extends Component {
  constructor(props) {
    super(props);
    this.state = {
      input: '',
      isValid: false
    }
  }


handleInputText=(input)=>{
  this.setState({input})
  if(input ==='' || input.length < 0)
  this.setState({isValid:false})
  else{
    this.setState({isValid:true})
  }

}
  render() {
    return (
     <View>
       <TextInput
       value={this.state.input}
       onChangeText={this.handleInputText}
       />
       <View>
         <Button title='submit' disabled={!this.state.isValid}/>
       </View>
     </View>
    )
  }
}

export default class App extends Component{
  render(){
    return(
      <Home/>
    )
  }
}





No comments:

Post a Comment