user2086641
user2086641

Reputation: 4371

submit django form on checkbox select

tml:

<div id="report-liveonly">
  <form action="." id="status" method="POST">{% csrf_token %}
  <p>{{SearchKeywordForm.status}}Only show LIVE reports</p>
  </form>
</div>

I am trying to submit the searchform on checkbox click.It is not working. Onclick also not happening,i checked with alert message.

The total function is to show the live report,if Only show LIVE reports checkbox is checked.

Need help

Upvotes: 2

Views: 3528

Answers (1)

user2086641
user2086641

Reputation: 4371

I found the solution,

class SearchKeyword(Form):
    search_keyword = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Keyword Search','class':'keyword-search'}))
    status = forms.BooleanField(widget=forms.CheckboxInput(attrs={'onclick':'this.form.submit();'}),required=False, label="Status")

Upvotes: 9

Related Questions