1.0.4 • Published 6 years ago

react-native-validate-textinput v1.0.4

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

react-native-validate-textinput

Validate TextInput custom for React native (same Redux form) validate-textinput

Installation

$ npm install react-native-validate-textinput --save

Usage

'use strict';

var React = require('react-native');
var {
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
} = React;

import ValidateTextInput from "react-native-validate-textinput";

class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {
      valueInput: ""
    };
  }
  
  _onProcessTextChange(currentText){
        if(!currentText){
          this.setState({
            errorText: 'Không được để trống'
          })
        } else if(!currentText.includes("@") && currentText){
          this.setState({
            errorText: 'Phải chứa ký tự @'
          })
        } else if(currentText.length < 8 && currentText){
          this.setState({
            errorText: 'Phải lớn hơn 8 ký tự'
          })
        }
        else{
          this.setState({
            errorText: ''
          })
        }
  }

  render() {
    return (
        <View style={styles.container}>
            <Image source={background} style={styles.shadow}>
              <View style={styles.bg}>
                <ValidateTextInput
                  errorItem={this.state.errorText}
                  typeInput={"email"}
                  // styleIcon={{
                  //   color: 'red'
                  // }}
                  onChangeTextInput={(text) => {
                    this._onProcessTextChange(text);
                    this.setState({
                      valueInput: text
                    })
                  }}
                  hiddenIcon={false}
                  typeErrorView={"bottomInput"}
                  hiddenIconErrorView={true}
                />

                <ValidateTextInput
                  errorItem={this.state.errorText}
                  typeInput={"password"}
                  // styleIcon={{
                  //   color: 'red'
                  // }}
                  onChangeTextInput={(text) => {
                    this.setState({
                      valueInput: text
                    })
                  }}
                  hiddenIcon={false}
                />

                <Button
                  style={styles.btn}
                  onPress={() => this.props.navigation.navigate("Home")}
                >
                  <Text>Login</Text>
                </Button>
              </View>
            </Image>
        </View>
    );
  }
}

export default Login;

Properties

Note: Other properties will be passed down to underlying component.

PropDescriptionTypeDefault
autoFocusIf true, focuses the input on componentDidMount.boolfalse
autoCapitalizeCan tell TextInput to automatically capitalize certain characters.boolfalse
editableIf false, text is not editable. The default value is true.boolfalse
secureTextEntryIf true, the text input obscures the text entered so that sensitive text like passwords stay secure. The default value is false. Does not work with 'multiline={true}'.boolfalse
underlineColorAndroidThe color of the TextInput underline.colortransparent
placeholderThe string that will be rendered before text input has been entered.stringEnter text...
placeholderTextColorThe text color of the placeholder string.colorgray
multilineIf true, the text input obscures the text entered so that sensitive text like passwords stay secure. The default value is false. Does not work with 'multiline={true}'.booltrue
maxLengthLimits the maximum number of characters that can be entered. Use this instead of implementing the logic in JS to avoid flicker.intNone
disableFullscreenUIWhen false, if there is a small amount of space available around a text input (e.g. landscape orientation on a phone), the OS may choose to have the user edit the text inside of a full screen text input mode. When true, this feature is disabled and users will always edit the text directly inside of the text input.boolfalse
allowFontScalingSpecifies whether fonts should scale to respect Text Size accessibility settings.booltrue
autoCorrectIf false, disables auto-correct.booltrue
caretHiddenIf true, caret is hidden.boolfalse
enablesReturnKeyAutomaticallyIf true, the keyboard disables the return key when there is no text and automatically enables it when there is text.boolfalse
typeInputType TextInput. Value valid: email, password, defaultNoneemail
hiddenIconIf true, hide icon in custom view of TextInput.boolfalse
renderIconCustom Icon view for view input.funcNone
onChangeTextChange value text input, setState value text input.funcNone
backgroundColorErrorViewChange background color for error validate view.color#DA0967
colorErrorTextChange color error text.color#fff
customValidateIf true, custom validate value text input.boolfalse
typeErrorViewType error view when validate text input. Vaue valid: design, bottomInput .stringdesign
sizeErrorTextChange fontSize error text.number13
hiddenIconErrorViewIf true, hide icon in error view.boolfalse

Style props

Custom style input

  • Custom style TextInput default
styleInputDefault: {
        color: '#000',
        height: 40,
        fontSize: 14,
        // width: WINDOW_WIDTH,
        backgroundColor: 'transparent',
        paddingLeft: 10
 },
  • Custom style TextInput email
styleInputEmail: {
      color: '#000',
      height: 40,
      fontSize: 14,
      // width: WINDOW_WIDTH,
      backgroundColor: 'transparent',
      paddingLeft: 10
 },
  • Custom style TextInput password
styleInputPassword: {
      color: '#000',
      height: 40,
      fontSize: 14,
      // width: WINDOW_WIDTH,
      backgroundColor: 'transparent',
      paddingLeft: 10
 },

Custom style item

styleItem: { 
       alignItems: "center",   
       borderWidth: 1,
       backgroundColor: '#ededed',
       borderRadius: 5,
},

Custom style icon

styleIcon: { 
     color: '#000',
     fontSize: 22, 
     backgroundColor: "transparent", 
     alignItems: "center",
     marginRight: 5,
     marginLeft: 5
},