Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

476
Vistas
How to convert string to lowercase? .toLowerCase() not working properly

I want to make an input field that returns imputed text in lower case. I'm using expo

const [login, setLogin] = useState('');
//...
<TextInput style={{backgroundColor:'#bbb'}}
   value={login}
   onChangeText={(val)=>setLogin(val.toLowerCase())}
   placeholder="email or username"
></TextInput>

I'm getting a strange result when testing it on my device.

my input: 'K' => login = 'k'

my input: 'k' => login = 'kkk'

my input: 'k' => login = 'kkkkkkk'

You may need to try a few times to recreate my result as it doesn't happen every time. When I remove .toLowerCase(), it works correctly.

I made runnable example for you to test. Running it in web mode works fine, but when I run it on my device, the same error is occurring as in my project.

Here is a video of what's happening to me when I run it on android 10. You can see that it doesn't happen always, but sometimes it registers as if I've pressed "q" three times when I've only pressed it twice

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think you run into a known react-native bug, related to text inputs and capitalization on Android platform. Open github issue #27449.

As a workaround you can force the text input to use the visible-password keyboard type on Android.

Working example for you to test:

import React, { useState } from 'react';
import { Text, View, StyleSheet, TextInput } from 'react-native';
import { Platform } from 'react-native';

export default function App() {
  const [login, setLogin] = useState('');
  return (
    <View style={styles.container}>
      <TextInput style={{backgroundColor:'#bbb'}}
        value={login}
        onChangeText={(val)=>setLogin(val.toLowerCase())}
        keyboardType={Platform.OS === 'ios' ? 'default' : 'visible-password'}
        placeholder="email or username"
      ></TextInput>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    padding: 80,
  },
});

Credit for the workaround goes to simon-davies-avtura

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda