react-native-masked-text icon indicating copy to clipboard operation
react-native-masked-text copied to clipboard

rawText returning undefined

Open rdgomt opened this issue 5 years ago • 7 comments

Hello. I'm trying to use rawValue for saving in state, but always get undefined. maskedValue returns correct.

<TextInputMask
    customTextInput={TextInput}
    customTextInputProps={{
       mode: 'outlined',
          label: 'CPF',
       }}
    type={'cpf'}
    value={this.state.cpf}
    includeRawValueInChangeText={true}
    onChangeText={(maskedText, rawText) => {
        console.log(maskedText, rawText)
        this.setState({ cpf: maskedText })
    }}
/>

Using 1.12.0 version.

rdgomt avatar Jun 22 '19 00:06 rdgomt

Also having this issue.

image

Using 1.12.3 version

image

giu-lia avatar Jun 23 '19 23:06 giu-lia

Same here !

monceeef avatar Jul 02 '19 09:07 monceeef

Hi guys!

I'm trying this sample:

export default class WithRawValueInChangeText extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      value: '',
      raw: ''
    }
  }

  render() {
    return (
      <View style={container}>
        <Text>With raw value in change text</Text>
        <TextInputMask
          type={'cpf'}
          value={this.state.value}
          includeRawValueInChangeText={true}
          onChangeText={(text, rawValue) => {
            this.setState({
              value: text,
              raw: rawValue
            })
          }}
        />
        <Text>Value: {this.state.value}</Text>
        <Text>Raw: {this.state.raw}</Text>
      </View>
    )
  }
}

And it's working properly =/.

image

Could you provide some additional info, like:

  • Are you using typescript?
  • Device and OS versions

If you want, you can check this repo: https://github.com/benhurott/react-native-masked-text-samples

bhrott avatar Jul 21 '19 21:07 bhrott

It doesn't works with phone number or custom mask. Captura de Pantalla 2019-08-20 a la(s) 6 10 32 p  m

ckristhoff avatar Aug 20 '19 23:08 ckristhoff

Hi guys!

I'm trying this sample:

export default class WithRawValueInChangeText extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      value: '',
      raw: ''
    }
  }

  render() {
    return (
      <View style={container}>
        <Text>With raw value in change text</Text>
        <TextInputMask
          type={'cpf'}
          value={this.state.value}
          includeRawValueInChangeText={true}
          onChangeText={(text, rawValue) => {
            this.setState({
              value: text,
              raw: rawValue
            })
          }}
        />
        <Text>Value: {this.state.value}</Text>
        <Text>Raw: {this.state.raw}</Text>
      </View>
    )
  }
}

And it's working properly =/.

image

Could you provide some additional info, like:

  • Are you using typescript?
  • Device and OS versions

If you want, you can check this repo: https://github.com/benhurott/react-native-masked-text-samples

it would be great if it works on every type not only cpf

sorakrisc avatar Dec 12 '19 08:12 sorakrisc

Do you have any ideas how to fix it?

SmirnovM91 avatar Mar 02 '20 14:03 SmirnovM91

Do you have any ideas how to fix it?

Yeah, this object is a type NativeSyntheticEvent<TextInputChangeEventData> for get value use: value.nativeEvent.text

Or

use onChangeText, instead of onChange

nandobas avatar Jan 28 '21 14:01 nandobas