I’m currently writing a ToDo-Script for a project i have running.
Now there is some (in this case) annoying behavior of some Browsers (e.g. Firefox), they remember previous form data. This feature sure can be handy but if you write a ToDo-Script which relies on Checkboxes, it’s simply annoying.
My problem is, that the Browser remembers the form data and sets the checked state as it was last time. This can be inaccurate (e.g. when multiple people are editing at the same time and a simple refresh doesn’t do the job).
is there a way to set the actual checked state by the html attribute “checked” you get from the django template?
here is what I do in my django-template:
{% for t in todos %}
<div class='todo_div'>
{% if t.is_done %}
<input type='checkbox' name='{{ t.pk }}' class='todo_checkbox' value='{{ t.pk }}' checked='true' />
{% else %}
<input type='checkbox' name='{{ t.pk }}' class='todo_checkbox' value='{{ t.pk }}'/>
{% endif %}
{{ t.text }}
</div>
{% endfor %}
You can use the
attribute on your input but this is unreliable.
The best way is to randomize your form input names. Each time the form is rendered, you could generate a random string like “klsdjhfsdf”. Then, name your input like this:
Server-side you parse the received inputs and look at everything after the first hyphen to get the input name.