Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Form Request.GET only get 1 value from multiple selected field

I have a multi select field using select2 in my form, i want to get all the value selected when submit, but when I print the value, its only get the value of the last selected option, how can i fix this?

Any help is much appreciated, below is my code :

html

<select class="js-example-basic-multiple" name="Project" multiple="multiple" style="display:inline-block;">
    <option value="ALL" checked="1">ALL</option>
    <option value="1">a</option>
    <option value="2">b</option>
    <option value="3">c</option>
    <option value="4">d</option>
</select>

<script>
    $('.js-example-basic-multiple').select2();
    $('.js-example-basic-multiple').on('change', function() {
    var a = $('.js-example-basic-multiple').val();
})
</script>

view.py

if 'Project' in request.GET:
    print(request.GET['Project'])
like image 749
M.Izzat Avatar asked Nov 23 '17 06:11

M.Izzat


1 Answers

UPDATE: Thanks to @Blurp, I just change request.GET['Project'] to request.GET.getlist('Project')

like image 89
M.Izzat Avatar answered Nov 08 '22 10:11

M.Izzat