Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Allow only lowercase input for TextInput

Tags:

react-native

Is it possible to have a TextInput for react native that allows only lowercase input?

As of now, tried this code:

state = { login: '' }

changeUsernameToLowercase = (input) => {
  var temp = input.toLowerCase()
  this.setState({login: temp})
}

<TextInput
  onChangeText={(login) => this.changeUsernameToLowercase(login)}
  value={this.state.login}
  autoCapitalize='none' />

But it seems to not work on some android devices.

Maybe there is a more efficient way on doing this?

like image 506
Dale Moncayo Avatar asked Oct 29 '18 03:10

Dale Moncayo


1 Answers

This might solve your problem, it works for me.
Add these three lines inside TextInput, original answer source

 autoCapitalize="none"
 secureTextEntry={true}
 keyboardType={"visible-password"}

example

import React, { useState } from "react";
import { View, TextInput } from "react-native";


export default function App () {
    const [text,setText] = useState('');
    
    return (
      <View>
        <TextInput
           autoCapitalize="none"
           secureTextEntry={true}
           keyboardType={"visible-password"}
          style={{height: 40, borderColor: 'gray', borderWidth: 1,width:"100%"}}
          value={text}
          onChangeText={ text => setText(text.toLowerCase()) }
        />
      </View>
    );
}
like image 79
shubham jha Avatar answered Dec 23 '22 21:12

shubham jha