Use Case:
I have a use case where the User can paste ONE of the following string(s) in
textAreaand it must be formatted to new Line:
- Comma-space (E.g: 12, 2, 3)
- Comma-newline (E.g: 12,\n2,\n3,\n)
- Newline (E.g: 12\n2\n3\n)
I'm trying to use onPaste functionality but not sure how to Integrate this use case with React textarea onPaste
I have this sanitzation util that takes paste input (string) and returns an array
function sanatizeToArray(str){
str=str || "";
str = str.replaceAll(" ",""); // get rid of spaces!
str = str.replaceAll("\n",","); // change new lines into commas
str = str.replaceAll(",,",","); // get rid of duplicates
return str.split(","); // break it down!
}
sanatizeToArray("12, 2, 3"); // Prints ["12", "2", "3"]
sanatizeToArray("12,\n2,\n3,\n"); // Prints ["12", "2", "3", ""]
sanatizeToArray("12\n2\n3\n"); // Prints ["12", "2", "3", ""]
I would really appreciate if someone can help integrate this sanitizeArray function with onPaste.
onChange?onPastecuz the user is expected to copy paste one of these three formats: codesandbox.io/s/money-input-example-forked-vsom5?file=/src/… First one works, however second and third doesn't .. But the util seems to be working fine if i run in console individually :(\nwhen you copy paste the second use case in text area (which isn't expected :( don't know whats going on.