SelectInput multiple=True

5 views
Skip to first unread message

ezra.j.rice

unread,
May 21, 2018, 1:59:54 PM5/21/18
to Tethys Platform
I am attempting to use the multi select input gizmo, but cannot seem to get it to POST multiple selected values.

Gizmo creation code:
multi_select_input = SelectInput(display_text='Multi Selection',
                              name='multi_select',
                              multiple=True,
                              options=[('One', '1'), ('Two', '2')],
                              initial=['2'])
Pulling data from POST request:
if request.POST:
    input_selected = request.POST.get('multi_select', None)

The output of print(input_selected) is '2' when I had selected '1' and '2' prior to submitting.
Any ideas on why the gizmo doesn't send the entire list of selected options?

Brown, Dustin T ERDC-RDE-CHL-MS CIV

unread,
May 21, 2018, 2:16:40 PM5/21/18
to ezra.j.rice, Tethys Platform

Try using the getlist() function: request.POST.getlist(“multi_select[]”).

--
You received this message because you are subscribed to the Google Groups "Tethys Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tethysplatfor...@googlegroups.com.
To view this discussion on the web visit Blockedhttps://groups.google.com/d/msgid/tethysplatform/77b9a134-ce30-4a33-a67d-345e3add8bab%40googlegroups.comBlocked.
For more options, visit Blockedhttps://groups.google.com/d/optoutBlocked.

ezra.j.rice

unread,
May 21, 2018, 3:05:40 PM5/21/18
to Tethys Platform
Thanks Dustin! That got me really close to the solution. PHP requires the brackets, but for some reason that gave me an empty list whereas request.POST.getlist("multi_select") gave me the list of selected options.
Reply all
Reply to author
Forward
0 new messages