dimanche 6 décembre 2015

Reading data of multiple level of multiple checkboxes in Django

I have a page that is something like below:

<table>
    <tr>
        <th>ID</th>
        <th>Edit</th>
    </tr>
    <form action="/edit_submit/" method="POST">
    {% for item in result %}
    <tr> 
        <td>{{ item.id }}</td>
        <td>
            <input type="checkbox" name="options" id={{ item.id }} value="1">Apple
            <input type="checkbox" name="options" id={{ item.id }} value="2">Water
            <input type="checkbox" name="options" id={{ item.id }} value="3">Cake
            {% csrf_token %}
        </td>
    </tr>
    {% endfor %}
</table>
<input type="submit" value="Submit">    
</form>

I need a way to read all the checkboxes value with name options on the page during submit, without knowing the item.id values. Hence I need an output which gives me tuples as item.id,value,checked.

I know that id is not unique here, however is there a better solution for grouping checkboxes? I can put item.id as name in html, but remember I do not know the item.id which appeared on the page.

Aucun commentaire:

Enregistrer un commentaire