css - How can I work around the need for Bootstrap 3's form-control class? -


i decided try out bootstrap 3 tonight first time. noticed that, in order default, pretty form field styling, need add form-control class each input, textarea, select, etc. pain dynamically generate forms (e.g., using django). django allows set attributes of form fields, globally require nasty monkey patch or else non-dry code.

  1. is there way avoid requirement of class, still retaining basic form field styles?
  2. is there quick way (preferably non-js) address otherwise?

you realy should check django app render django forms nice boostrap forms, using tag in template.

its name django-bootstrap3. here's how use it:

  1. install django-bootstrap3
  2. add bootstrap3 installed_apps:

    installed_apps = (     ...     'bootstrap3',     ... ) 
  3. update template:

    1. load bootstrap3
    2. replace {{form.as_p}} {% bootstrap3_form form %}

before:

<form method="post" class="form-horizontal" action="" >     <div class="hidden-desktop">       <button type="submit" class="btn btn-primary"> save</button>     </div>     {% csrf_token %}     {{ form.as_p }}     <div class="actions form-actions">       <button type="submit" class="btn btn-primary"> save</button>     </div>  </form> 

after:

{% extends "base.html" %}  {% load bootstrap3 %}  <form method="post" class="form-horizontal" action="" >   <div class="hidden-desktop">     <button type="submit" class="btn btn-primary">{% bootstrap_icon "ok" %} save</button>   </div>   {% csrf_token %}   {% bootstrap_form form  %}   <div class="actions form-actions">     <button type="submit" class="btn btn-primary">{% bootstrap_icon "ok" %} save</button>   </div> 

nothing else do. nothing update in form. no javascript hacks.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -