Hey,
I have a multiple dropdown menue and insert the data of the clicked checkboxes in a RichTextField in the database.
Is there any way to convert the text from this style:
[
“apple”,
“banana”,
“something”
]
into this ?
Maybe with some html ?
J.D
October 6, 2020, 2:26pm
2
Is the first one a string or an array?
J.D
October 7, 2020, 7:32am
4
@nickoertel so:
let originalString =
`[
"apple",
"banana",
"something"
]`;
let arr = originalString.split('"');
arr.pop();
arr.shift();
arr = arr.filter(e => e.trim() !== ",");
let newString = "• " + arr.join("\n• ");
@jonatandor35 Hey, I tried your code, but I don’t get the bullet points.
Let me explain, what I’m trying to do.
I have a multiple checkbox menu in a custom form:
You can check 0 - 3 checkboxes (you don’t have to check them)
When I insert the data into my database
"fieldkey": $w("#checkboxGroup1").value,
I get this as result:
[
“apple”,
“banana”,
“something”
]
But I want to convert it into this style:
I can also use single checkboxes, if it would be easier to code.
J.D
October 12, 2020, 2:42pm
6
@nickoertel I asked you if it’s a string or an array and you said it was a string. Now it looks like it an array. So first make sure that is and then we’ll be able to proceed.
@jonatandor35 Hey, sorry about this.
I had an idea and it worked, here’s my result
Go to your checkboxGroup and insert YourText as value
Then use this code (for example in the insert function)
const toInsertDatabase = {
"fieldKey": "<ul>" + $w('#checkboxGroup1').value.toString() + "</ul>"
};
J.D
October 12, 2020, 11:16pm
8
@nickoertel I see. the question is what you’re trying to do with these values. If you want to use them as html then your code is fine.
Another direction is to use the value without
, and to write:
const toInsertDatabase = {
"fieldKey": `<ul><li>${$w("#checkboxGroup1").value.join("</li><li>")}</li></ul>`
};