django - Normal Buttons for ChoiceField -


software versions: using django 1.7 , python 3.4

i using django form handle user input validation , processing. in form, have choicefield want display using normal buttons instead of radio buttons or select input element. writing html myself template, rather using form passed context of template render html.

here html field:

<form method="get" action=".">     <div id="div_id_session_type">         <div class="controls btn-group" role='group'>             <input type="button" class='btn' name="session_type" id="id_session_type_1" value="individual">             <input type="button" class='btn' name="session_type" id="id_session_type_2" value="small group">             <input type="button" class='btn' name="session_type" id="id_session_type_3" value="class">         </div>     </div>     <input class='btn' type="submit" value="search"> </form> 

when submit form after choosing button, form not recognize input session_type field (my choicefield).

however, if change type="button" type="radio" on of input buttons, form accept choice, turns buttons radio buttons, don't want.

how can keep choices full buttons , still have form accept input?

i found workaround using hidden radio buttons , making label appear button.:

<form method="get" action=".">     <div id="div_id_session_type">         <div class="controls btn-group" role='group'>             <label for="id_session_type_1" class="btn">individual</label>             <input type="radio" class='hidden-radio' name="session_type" id="id_session_type_1">             <label for="id_session_type_2" class="btn">small group</label>             <input type="radio" class='hidden-radio' name="session_type" id="id_session_type_2">             <input type="radio" class='hidden-radio' name="session_type" id="id_session_type_3">             <label for="id_session_type_3" class="btn">class</label>         </div>     </div>     <input class='btn' type="submit" value="search"> </form> 

and css

input[type="radio"].hidden-radio {   display: none; } 

i have jquery adding css classes labels on click in order change appearance of selected label. seems working well.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -