How to save multiple values with plugin select2 as one field in database
How to save multiple values with plugin select2 as one field in database
Koen Verhoeven
Posts: 25Questions: 7Answers: 0
I've got the following js code to select multiple options.
{
"label": "Bodemvocht:",
"name": "bodemvocht",
"type": "select2",
"options": [
{ "label": "", "value": "" },
{ "label": "Droog", "value": "Droog" },
{ "label": "Vochtig", "value": "Vochtig" },
{ "label": "Nat", "value": "Nat" },
{ "label": "Geen voorkeur", "value": "Geen voorkeur" }
],
"opts": {
"placeholder": "Selecteer vochtigheid",
"multiple": "multiple",
"separator": ";",
"allowClear": true
}
But when saving this I get an error (Array to string conversion) and only the text 'Array' is saved in the database. How to solve this properly?
Thanks for your help!
This discussion has been closed.
Answers
I don't think that Select2 actually has a
separator
option does it? The Select2 docs suggest not. There is howevertokenSeparators
which I think will do what you are looking for.Alternatively, I have an updated version of the Select2 plug-in for Editor which does have its own
separator
option that I could send over? It hasn't been published yet.Regards,
Allan
Allan, thanks for your answer and sorry for the late reply! I expected (and didn't get) an email notification of your post. I got the separator option from https://editor.datatables.net/plug-ins/field-type/editor.select2. I tried tokenSeparators but it still wouldn't work unfortunately.
I have been troubleshooting some time but it still isn't functioning. I'm certainly interested in the updated select2 plug-in (or some other solution).
Sent you a PM with it. I'll be publishing it probably next week.
Allan
Hi Allan,
Again sorry for the late reply. Based on your example script the problem was fixed simply by moving this --> separator: ";" <-- upwards from the 'opts' part to the 'main settings' part. Works perfect now. Thanks a lot!
Koen