Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

When setFieldValue RN InputMasked crashed #329

Open
yuriedmundo opened this issue Nov 25, 2020 · 2 comments
Open

When setFieldValue RN InputMasked crashed #329

yuriedmundo opened this issue Nov 25, 2020 · 2 comments

Comments

@yuriedmundo
Copy link

I have a step-by-step registration screen.
I show the component on the screen like this:

{step === 1 &&
<Component1 />
}
{step === 2 &&
<Component2 />
}

I go to step 2 and then back to step 1 I use the function setFieldValue to keep the value in the input.

But Input Masked gives an error.
Only Masked, Simple Input is ok.

Can you help me?

image

  • My InputMasked

image

  • My Input

image

@carlosallexandre
Copy link

@yuriedmundo,

It seems when you back that the ref isn't attached yet.

Try put the setValue of inputMask like below

setValue(ref: InputValueReference, value:string) {
  inputValueRef.current.value = value;
  // next line changed
  inputElementRef.current?.setNativeProps({ text: value });
}

Let me updated if it worked or not.

@AllyssonAlas
Copy link

@yuriedmundo,

It seems when you back that the ref isn't attached yet.

Try put the setValue of inputMask like below

setValue(ref: InputValueReference, value:string) {
  inputValueRef.current.value = value;
  // next line changed
  inputElementRef.current?.setNativeProps({ text: value });
}

Let me updated if it worked or not.

I'm having the same issue, with the input configuration provided by documentation (https://unform.dev/examples/react-native-input-mask), is not possible to adjust the line as you instructed, it shows this error Parsing error: Optional chaining cannot appear in left-hand side, this issue only happens with exchangeable forms and only inputs with mask, but not with "common" forms or common inputs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants