Editor and Select2-plugin: Create extra options 'on-the-fly'
Editor and Select2-plugin: Create extra options 'on-the-fly'
Probably I'm asking to much, but is there any efficient way to allow the 'creation' of new options (coming from a MJOIN in the Editor) with the option "createTag" which comes with the select2-component?
Or am I a bit too optimistic now ?
I would like to be able to create 'new tags' on the fly in the editor when editing a record.
This possible in select2 when using "createTag" option, but I don't know if it's worth the effort to try and figuring this out in combination with the Editor?
This question has an accepted answers - jump to answer
Answers
Hi Arthur,
I don't have it for "select2", but for "selectize" which is similar. There is an Editor plugin for selectize, too. You might want to use that as well. I use both by the way. They are not that much different actually.
This is what it looks like in my code:
The "createFilter" returns an existing "id" if an existing option is selected. It returns "false" if no existing option is selected. That is the case if the field value is not numeric or it contains a period.
On the server I need to filter out the newly entered counterparties on "writeCreate" and on "writeEdit" - and INSERT them into the database.
Thank you so much for this answer, rf1234!
Your way of reasoning is perfectly clear and I will start implementing your logic (first with select2, but selectize looks very promising as well) right away!!
(Still discovering new aspects of Datatables and Editor thanks to people like you! Great way to keep learning!)
Glad I could help! Please share your select2 solution for this once you have it ready. I came from using "selectize" and chose "select2" for options grouping with collapsible optgroups which turned out to be rather difficult. Eventually got it working.
To make select2 look the same as selectize I use this CSS so that it is indistinguishable from a user's point of view. This allows me to use "select2", "selectize" and the Editor built-in "select" field types in parallel - depending on the use case.