-
Notifications
You must be signed in to change notification settings - Fork 4
Add the ability to get the raw value before applying the mask #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @NotatNiiK . I don't think it's a good idea to add logic to bypass the mask formatting. This library was created with the idea of formatting, if you don't need it, you can use plain text input from react-native. But if you need formatting with special characters, then you better add them as If that didn't work for you, could you send me the code, I'd take a look at it and maybe suggest a solution. Thanks 🙂 |
I don't need to bypass the mask, I need the ability to get the raw value before the mask is applied. I need this when working with native paste. Because if I use a custom button to paste text from the clipboard into input, I can directly get it and format it as I need (by reading the value from the clipboard), but with native paste, I can't do that (for example, on IOS, above the keyboard, it can automatically pull up your phone number from your profile). In this example, I have a mask of the type [000] [00] [00] [00] [000] set, but if I get a value of the type [00000] [00] [00] [00] [00] [000] from native paste, then this mask automatically cuts off the last two characters and in the future it interferes with the work of the handleOnPaste function
|
@NotatNiiK In this case you shoud use const AFFINITY_FORMAT = ["[00000] [00] [00] [00] [00] [000]"];
<MaskedTextInput mask="[000] [00] [00] [00] [000]" affinityFormat={AFFINITY_FORMAT} /> Also, you could play with a different Screen.Recording.2025-04-10.at.11.36.45.mov |
affinityFormat doesn't suit me, because I don't need to be able to enter a phone number in this format |
@NotatNiiK Could you please provide code that I can run and get the expected behavior, or describe what you mean by a raw value? I'm asking this because my library already provides two values in onChangeText formatted and unformatted values, and your problem is not quite clear to me. So perhaps you need a direct handler from my MaskedTextInput? It would be similar to onPaste and would be called when the user inserts text into the TextInput? |
@NotatNiiK I did a small investigation.
So, there is an open PR facebook/react-native#45425 to add this logic in react-native. Your code with a fix will be: const phoneNumberCallback = async (value, rawValue) => {
const isPasted = _value?.replace(/[^+\d]/g, '').length - phoneNumberValue.length > 1
if (isPasted) {
const pastedRawValue = await Clipboard.getText();
handleOnPaste(pastedRawValue)
setIsFocusedPhoneNumber(true)
phoneNumberInputRef?.current?.focus()
if (callback) callback(value)
return
}
....
} Please, let me know if it helps. |
Add the ability to get the raw value without applying a mask, for example, with the 3rd argument to onChange or something else. I encountered problems with native paste into the input, where the mask is immediately applied to the inserted value
The text was updated successfully, but these errors were encountered: