Hi Team,
I am using the "InputNumberMask" widget in our application, The widget pastes the value on the frontend screen when text with a line break is pasted on any input with a regex pattern, but the value is not binded into the input variable. As a result, when we click outside of the input field, the validation persists, and the value is not correctly saved in the database.
If this content is copied:
Does anyone know how to fix this problem?
Regards,
Sagar R
Hi @Sagar R,
To fix the issue with the InputNumberMask not binding the value correctly after pasting content with line breaks, you can try the following:
1) Use JavaScript to sanitize input:
Add a JavaScript block that listens for the onPaste event, removes line breaks, and updates the input field value accordingly. Here’s an example:
document.querySelectorAll('input').forEach(input => {
input.addEventListener('paste', function(e) {
e.preventDefault();
let pasteData = (e.clipboardData || window.clipboardData).getData('text');
pasteData = pasteData.replace(/\n|\r/g, ''); // Remove line breaks
document.execCommand('insertText', false, pasteData);
});
2) Use OnChange event:
If the issue persists, ensure you’re handling the OnChange event properly. This event ensures that the value gets updated when the user clicks outside of the input field. Ensure that the widget’s variable is being refreshed upon change.
3) Update the Input Mask Reactive component:
If none of the above works, check for any updates in the Forge for the Input Mask Reactive component. The latest version might have bug fixes that resolve this issue.
Let me know if this resolves the issue!
Remove Line Breaks Before Pasting:
javascript:document.getElementById('your-input-id').addEventListener('paste', function(e) { e.preventDefault(); var text = e.clipboardData.getData('text/plain').replace(/[\r\n]+/g, ''); document.execCommand('insertText', false, text);});
Use the OnChange Event to Handle Line Breaks:
Replace(InputText, "\n", "")
Custom JavaScript or CSS:
code#your-input-id { white-space: nowrap; overflow: hidden;}
Try a Different Mask Plugin:
Validation and Error Handling: