Buy Now
Sign in

Dynamically add options to a multi-select field

megana , March 05 2019, 21:21
M
megana 192
March 05 2019, 21:21 #384457
I love how the dropdowns work in CF6, how I can either click the arrow to see the full list of options or just start typing and it will show me potential matches.
I would like to have a dropdown list where, if the user types something that has no match on the list, it is added to the top or bottom of the list for them to choose. I'm not sure if this would be done with the Event tab of the dropdown field or if some custom JS would be required. This would be for a dropdown with multi-select set to Yes, which I think makes it a bit more complicated.
Can anyone point me in the right direction?
EDIT: I just realized the dropdown field I was looking at has an autocomplete and that's why the functionality is so cool. I think that makes it still more complicated to do what I'm trying to do...
EDIT 2: I successfully modified the autocomplete to do this, but it only works if multi-select is set to No.
Here is the Custom Code I'm using:
<?php
$this->data['locations'] = $this->get("read_data11");
$this->data['locations'][$this->data("location")] = $this->data("location");
?>
{data/jsonen:locations}
I'm just not sure how I would modify this so that it works with multi-select set to Yes.
healyhatman 8
March 05 2019, 21:28 #384458
That's not possible with vanilla CF, you'd have to code that in yourself.
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
M
megana 192
March 05 2019, 21:44 #384459
I thought I might, I was hoping to get some guidance. The auto complete is kind of stumping me because I'm not sure how to debug what that event is doing or what the data that it gets from the form looks like, when a multi-select is involved.
Setting aside the part about adding things to the list based on what the user types, is a multi-select with autocomplete even possible?
M
megana 192
March 05 2019, 21:44 #384460
I thought I might, I was hoping to get some guidance. The auto complete is kind of stumping me because I'm not sure how to debug what that event is doing or what the data that it gets from the form looks like, when a multi-select is involved.
Setting aside the part about adding things to the list based on what the user types, is a multi-select with autocomplete even possible?
admin 27
March 08 2019, 08:25 #384564
Hi megana,
I understand you want the dropdown to "auto complete" on typing, and the ability to add new options, both are possible, but the 2nd is not implemented and can be added as a new feature to the next update!
The auto complete feature has a demo form, did you check it ?
Best regards
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
M
megana 192
April 05 2019, 02:26 #385568
Hi Max,
Very slow response on my part, but yes I checked out the demo and I have the auto complete working great and also the ability to add new options, however if I set Multi Select to Yes then the auto complete no longer works. The three things I'm trying to have work together on a single dropdown:
1) Auto complete
2) Add new options
3) Multi Select
I've got the first two working, but can't figure out how to add the third. As soon as I set Multi Select to Yes and add brackets after my field's name, the autocomplete won't work anymore. Any tips?
Thanks,
-Megan
admin 27
April 07 2019, 22:31 #385729
Hi Megan,
You need to adjust the "Read data" of the auto completer correctly in that case, with "multi select" the value passed is an array, I did not try it myself before but you need to adjust the code!
Best regrads
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!