How can I create a select list with an option for free text when option is not in list?

How can I create a select list with an option for free text when option is not in list?

Koen VerhoevenKoen Verhoeven Posts: 25Questions: 7Answers: 0

I've got a select list with about 20 options. This list contains the most common values, but it also should be possible to enter a new value which is not in the list. How should I do this?

For example, my list is

{
"label": "Soort:",
"name": "soort",
"type":  "select",
"options": [
   "Option1",
   "Option2"
]
},

And users should be able to type a free Option3.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    The Select2 plugin allows for entering new "tags". You woulds need to enable 'tags'.

    Kevin

  • Koen VerhoevenKoen Verhoeven Posts: 25Questions: 7Answers: 0

    Thanks, that was the easiest solution I could think of!

    So for others looking for the same thing: I added the select2 plugin, select2 library and css as described in the link provided by Kevin.

    After that I added the 'tag' option to the select2 type. See example below:

    {
                    "label": "Soort:",
                    "name": "soort",
                    "type":  "select2",
                    "opts": {
                        "tags": true                                                          
                    }   ,
                    "options": [
                        "Option 1",
                        "Option 2",
                        "etc"
                    ]
    },
    
This discussion has been closed.