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.
- is there way avoid requirement of class, still retaining basic form field styles?
- 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:
- install django-bootstrap3
add
bootstrap3
installed_apps
:installed_apps = ( ... 'bootstrap3', ... )
update template:
- load
bootstrap3
- replace
{{form.as_p}}
{% bootstrap3_form form %}
- load
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
Post a Comment