NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Controlled Input not working

Open rs6g10 opened this issue 5 years ago • 8 comments

Describe the bug Using native-base version 3.2.2. Following the documentation of Input specifically controlled input, I have found that I could never read the value of the input. Either the documentation is incorrect or the usage doesn't work.

To Reproduce Follow the example in documentation. Check the value in onChange method.

Expected behaviour Controlled input value is not being read.

CodeSandBox/Snack link The documentation example doesn't work.

Platform

  • NativeBase version - 3.2.2
  • Device: iPhone 12
  • OS: iOS 15
  • React Native version - 0.64.3
  • Expo sdk version - 43.0.2
  • node >= 16

rs6g10 avatar Nov 17 '21 12:11 rs6g10

@rs6g10 Can you check this implementation and see if this solves your problem? https://snack.expo.dev/@adityaj_geekyants/example

Ajamuar avatar Dec 01 '21 07:12 Ajamuar

Same issue I used onChangeText instead

abdul-abdu avatar Dec 06 '21 10:12 abdul-abdu

@rs6g10 Can you check this implementation and see if this solves your problem? https://snack.expo.dev/@adityaj_geekyants/example

Still doesn't work. event.target.value comes undefined on both iOS and Android. Works for web though. You can try with following simple example:

import React from "react"
import { Input, Text, Center, NativeBaseProvider } from "native-base"
export const Example = () => {
  const [inputText, setInputTextValue] = React.useState("")

  const handleChange = (event: any) => setInputTextValue(event.target.value)

  return (
  <>
    <Text>{inputText}</Text>
    <Input
      w={{
        base: "75%",
        md: "25%",
      }}
      onChange={handleChange}
      placeholder="Value Controlled Input"
    />
    </>
  )
}

export default () => {
  return (
    <NativeBaseProvider>
      <Center flex={1} px="3">
        <Example />
      </Center>
    </NativeBaseProvider>
  )
}

rs6g10 avatar Dec 08 '21 16:12 rs6g10

Same issue I used onChangeText instead

Thanks this works but you don't get the value from event.target.value.

rs6g10 avatar Dec 08 '21 16:12 rs6g10

@rs6g10 onChangeText prop takes a callback function that receives the input's text changes so event.target.value is not applicable there and if you want to use the onChange prop you can use event.nativeEvent. https://snack.expo.dev/@cyrus2505/nativebase-starter-snack

cyrus25 avatar Dec 09 '21 09:12 cyrus25

Please update the docs then: https://docs.nativebase.io/input#controlled-input

The controlled input seems to be wrong there

Facing the same issue.

NilsBaumgartner1994 avatar Dec 13 '21 15:12 NilsBaumgartner1994

this callback directly returns value

abdul-abdu avatar Jan 09 '22 16:01 abdul-abdu

@NilsBaumgartner1994 You can check the working example here. This will be updated in the docs soon.

cyrus25 avatar Jan 17 '22 13:01 cyrus25