{% load i18n %}
{{ form.poll_type.errors }} {{ form.poll_type.label_tag }} {{ form.poll_type }}
<div id="poll-answers-formset" style="display: none;">
  {{ form.poll_question.errors }} {{ form.poll_question.label_tag }} {{ form.poll_question }}
  <br>{% trans 'Poll answers' %}
  {{ pollformset.non_form_errors }}
  <table>
    {% for form in pollformset %}
      <tr>
        <td>{{ form.id }} {{ form.text }}</td>
        <td>{% if form.instance.pk %}{{ form.DELETE }}{% endif %}</td>
      </tr>
    {% endfor %}
  </table>
  {{ pollformset.management_form }}
</div>

<script type="text/javascript">
  $(function () {
    $('div#poll-answers-formset table tr').formset({
      deleteText:'{% trans 'remove answer' %}',
      addText:'{% trans 'add answer' %}',
      prefix: 'poll_answers'
    });

    var toggle_poll_answers_formset = function (poll_type) {
      if (poll_type == 0) {
        $('div#poll-answers-formset').hide();
      } else {
        $('div#poll-answers-formset').show();
      }
    }

    $('#id_poll_type').each(function () {
      toggle_poll_answers_formset($(this).val());
    }).change(function () {
      toggle_poll_answers_formset($(this).val());
    });
  });
</script>
{% load i18n %}
{{ form.poll_type.errors }} {{ form.poll_type.label_tag }} {{ form.poll_type }}
<div id="poll-answers-formset" style="display: none;">
  {{ form.poll_question.errors }} {{ form.poll_question.label_tag }} {{ form.poll_question }}
  <br>{% trans 'Poll answers' %}
  {{ pollformset.non_form_errors }}
  <table>
    {% for form in pollformset %}
      <tr>
        <td>{{ form.id }} {{ form.text }}</td>
        <td>{% if form.instance.pk %}{{ form.DELETE }}{% endif %}</td>
      </tr>
    {% endfor %}
  </table>
  {{ pollformset.management_form }}
</div>

<script type="text/javascript">
  window.onload = function () {
    $('div#poll-answers-formset table tr').formset({
      deleteText:'{% trans 'remove answer' %}',
      addText:'{% trans 'add answer' %}',
      prefix: 'poll_answers'
    });

    var toggle_poll_answers_formset = function (poll_type) {
      if (poll_type == 0) {
        $('div#poll-answers-formset').hide();
      } else {
        $('div#poll-answers-formset').show();
      }
    };

    $('#id_poll_type').each(function () {
      toggle_poll_answers_formset($(this).val());
    }).change(function () {
      toggle_poll_answers_formset($(this).val());
    });
  };
</script>
Fix onload function for poll for thirdparty (jquery loaded at the end of page, but template tries to work with $).
Fix onload function for poll for thirdparty (jquery loaded at the end of page, but template tries to work with $).
