[Django]-Django modelchoicefield submit

5👍

Submit the form on change

class CronForm(forms.Form):
    days = forms.ModelChoiceField(queryset=Date.objects.all().order_by('alias'), 
           widget=forms.Select(attrs={"onChange":'submit()'}))

And edit your template to

<form method=post>
👤rjv

2👍

Find the id of the dropdown using firebug. It should be id_days as you are using the name days. Then bind jQuery change event to it.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" >
    $(function(){
        $('#id_days').change(function(){
            $('#id_of_form').submit();
        });
    });
</script>

<form id="id_form" method="post" action="." name="form_name" >
    {{ days }}
</form>
👤arulmr

Leave a comment