django - How can I group a checkbox element with a number type element and work with it in html5? -


i creating app in django , have next problem:

in html5 template, have next structure represents kids , chocolate bars want eat.

{% kid_information in result %}      <br/><input type="checkbox" name="kid" id="kid" value="{{kid_information.name}}" />         <label for="kid"><b>{{ kid_information.name }}</b></label>             chocolate-bars: <input type="number" name="chocbars">   {% endfor %} <br/><br/> 

as can see, have 'for' structure represent list of kids have, , show name, , field let user select how many chocolate bars give each kid. want 'checkbox' structure, let user select kids , number of chocbars of each kid.

this inserted in 'form' structure, when click on "submit" button, treat selection in correspondent view.

in view, know if next, list of selected checkbox items:

selected_kids = request.post.getlist('kid')     selected_current_kid in selected_kids:      ... 

but problem want selected kids , specified chocolate bars each selected kid. how can in view? there way group checkbox element "kid" , "number" field?

looks don't use formset..

if use it, 1 of form fields kid_info, other 1 - amount. 1 form have info on 1 kid.

as see checkbox usage idea. if use chocolate amount input, ui seems win, changing amount 0 automatically mean checking child, avoiding unnecessary click on checkbox. , need check non-zero values.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -