One of the fields in my form allows users to input data either on a new line or separated by commas. However, when this data is sent via an API, a newline character (/n) is added for each new line which I do not want to display on the detail page. Here is an example of user input:
Example 1
ABC
red
test,blue
Example 2
abc,blue,
green,red
test
I need to ensure that any new line breaks are replaced with commas and existing commas are left unchanged.
Desired output:
Example 1
ABC,red,test,blue
Example 2
abc,blue,green,red,test
Here is the relevant code snippet:
createData(data) {
const Obj = {};
if (data.enum && data.value_type === 'Enum') {
Obj['values'] = data.enum.split(',');
}
console.log(Obj,"constraint");
return Obj;
}