tzangms / django-bootstrap-form Goto Github PK
View Code? Open in Web Editor NEWTwitter Bootstrap for Django Form
License: BSD 3-Clause "New" or "Revised" License
Twitter Bootstrap for Django Form
License: BSD 3-Clause "New" or "Revised" License
First, thanks a lot, this application is amazing.
I'm writing a Django open source project and using this application to improve user experience with twitter bootstrap.
So, there a problem with ChoiceModelFields when their values are filled, I don't know if this is properly a issue, but if you have passed for this before maybe you could help me.
Testing it, I putted a required ChoiceModelField in a form, filled and saved (In this case the field appears, cause there's no default value inputted)
When I tried to edit this form data the ChoiceModelField do not render in HTML DOM. When I tried to submit the form data, it is rendered with a required field error and no data filled.
I'm using the template tag {{ form|bootstrap }} instead do it field by field.
Do you have any idea that this can be?
best regards
João Dias de Carvalho Neto
Please add licensing information. May I suggest the BSD licence that the Django Project itself uses? https://code.djangoproject.com/browser/django/trunk/LICENSE
Hi
How do I get field types to work? So far I cant get the html5 date type to work.
Here is my code:
-- listingform.py ---
from django.db import models
from django.forms import ModelForm
from listings.models import Listing
class ListingForm(ModelForm):
class Meta:
model = Listing
fields = ['title', 'description', 'reward', 'contact', 'duration','conditions', 'expires', 'published']
---Models.py---
eg expires = models.DateField('date expires')
...others...
but the renderer doesn't seem to be picking up on that?
-- views.py --
def researchers(request):
form = ListingForm()
return render(request, 'listings/list.html', {'form': form })
Please help? Do I need to do more in the html file? currently just `{{ form|bootrap}}
Do I need to do more in the form class?
First, thanks for the package, saved me a bunch of time.
It might be nice to support a list of radio fields, which currently come out wrong if you use Django's RadioSelect
widget
I did it using code something like this: https://gist.github.com/2007671
You might want a different approach, though, looking at your forms.html
ahoy there! first of all thanks 👍
second: in
https://github.com/tzangms/django-bootstrap-form/blob/master/bootstrapform/__init__.py
you could do
from meta import VERSION
instead of
from bootstrapform.meta import VERSION
It works just as well, but that way people can put that module wherever
gracias
I always see this error in logs, I use:
django-bootstrap-form==3.2.1
pinax-theme-bootstrap==7.11.0
How required are being rendered? Is there any difference between requiered and not required?
I don't currently see a way for inline checkboxes:
Any way we can get that support added. Also, allowing the ability to pass a class to the top level of the form group (when the class "form-group" is) would help our styling + js functionality immensely!
for newcomers, it may be beneficial to add to the docs that it's up to the user/coder to download the bootstrap css/ images / js stuff and put it into their own static file paths.
Hi - thanks for package. It works nicely.
I found that for the css formatting to work correctly with BS 2.0 the
Hi,
I accidentally updated this library and now my system using bootstrap 1.4 does not display forms the way it used to. Checkboxes with labels that were listed down the page are now jumbled together. Are you going to offer either a versioned pypi package that I can install a specific version of or a setting to support one vs. the other? I can help with either of these if you'd prefer.
The package on pypi does not reflect recent changes. Please update package.
I'm getting error: 'unicode' object has no attribute 'visible_fields'
Exception Type: AttributeError
Exception Value:
'unicode' object has no attribute 'visible_fields'
Exception Location: /Users/nano/code/turpial/kooshi/kenv/lib/python2.7/site-packages/bootstrapform/templatetags/bootstrap.py in render, line 74
Do you know how could it be fixed?
When there are multiple help messages per field (eg. from multiple validators), the resulting output is formatted as an unordered list by django. When wrapped in:
<p class="help-block">
{{ field.help_text|safe }}
</p>
(templates/bootstrapform/field.html) this produces invalid HTML. As a result, the ul is pushed out of wrapping paragraph, the styling breaks etc.
I believe changing paragraph tag to div would be a pretty safe solution.
Hi,
I propose to change the tag library name and the template tags itself from "bootstrap" to "bootstrapform", as, in my opinion, bootstrap is a little too generic in this case (other bootstrap apps for django already exist)
cheers
Mauro
add_input_classes
should return field
to use it as a filter.
--- a/bootstrapform/templatetags/bootstrap.py
+++ b/bootstrapform/templatetags/bootstrap.py
@@ -45,20 +45,21 @@ def bootstrap_horizontal(element, label_cols='col-sm-2 col-lg-2'):
return render(element, markup_classes)
@register.filter
def add_input_classes(field):
if not is_checkbox(field) and not is_multiple_checkbox(field) \
and not is_radio(field) and not is_file(field):
field_classes = field.field.widget.attrs.get('class', '')
field_classes += ' form-control'
field.field.widget.attrs['class'] = field_classes
+ return field
I would open one-line PR if you want. Thanks.
New versions were released in 2017. However, the CHANGES.txt seems stuck in 2015 :-)
Currently, form rendering doesn't add the csrf token when rendering forms if you have django's CsrfViewMiddleware installed. It's kind of a pain in the butt to have to add that to every single form you want rendered. Why not check for installed apps and if CsrfViewMiddleware is installed, add the csrf_token by default since this will likely be the desired behavior? Then if you wanted, you could also create a form renderer that explicitly doesn't include the csrf hidden field when you don't want the csrf token:
{{ my_form|bootstrap_csrf_exempt }}
I don't mind doing the pull request for this, I just want to know why we wouldn't want to do this if there is a reason. What are other people's thoughts?
The documentation is not clear on this.
Getting this error in Django 1.11.2. It looks like the previous fix missed a use case. See https://github.com/tzangms/django-bootstrap-form/pull/82/files#r118964036 for more details.
I am trying to use the bootstrap_inline
filter with Bootstrap 2.3.1 and a formset. I suspect that it is not working because of twbs/bootstrap@f662dff and the changes that @Nivl made to bootstrapform/templates/bootstrapform/field.html. The forms' fields display inline correctly if I move them out of the "form-group" divs.
Since the filter is not documented, it is not clear whether it only works with BS3 by design or this is just a bug.
If you have your form split vertically, then django-bootstrap-form fails, as the row declarations clash.
For example the following will not render correctly because the row has already been split.
<form action="" method="post">{% csrf_token %}.
<div class="row">
{{ form.non_field_errors }}
<div class="col-md-6">
<fieldset>
<legend>Details</legend>
{{ form.part_number | bootstrap_horizontal }}
{{ form.grn | bootstrap_horizontal }}
{{ form.job_number | bootstrap_horizontal }}
</fieldset>
</div>
<div class="col-md-6">
<fieldset>
<legend>Cost and Quantity</legend>
{{ form.serial_number | bootstrap_horizontal }}
{{ form.qty | bootstrap_horizontal }}
{{ form.cost | bootstrap_horizontal }}
</fieldset>
</div>
</div><!-- end row div -->
<input type="submit" class="btn btn-default" value="Add or Update Carrier" />.
</form>
Note that adding a new row declaration doesn't seem to work either?:
<div class="row">
{{ form.non_field_errors }}
<div class="col-md-6">
<fieldset>
<legend>Details</legend>
<div class="row">
{{ form.part_number | bootstrap_horizontal }}
{{ form.grn | bootstrap_horizontal }}
{{ form.job_number | bootstrap_horizontal }}
</div>
</fieldset>
</div>
<div class="col-md-6">
<fieldset>
<legend>Cost and Quantity</legend>
<div class="row">
{{ form.serial_number | bootstrap_horizontal }}
{{ form.qty | bootstrap_horizontal }}
{{ form.cost | bootstrap_horizontal }}
</div>
</fieldset>
</div>
</div><!-- end row div -->
Looks like the fix for #77 got thwarted by an indentation error.
If you take a look at this compatibility code:
https://github.com/tzangms/django-bootstrap-form/blob/master/bootstrapform/templatetags/bootstrap.py#L80
It is actually under the else when it should be covering both cases. This causes the project to be Django 1.10 incompatible under certain circumstances.
PyPI package is a bit out of date. Please update.
Currently, I don't believe there's a way to output fieldsets. This would help make the markup more flexible.
Is there a good way to use bootstrap-datepicker or SelectDateWidget with django-bootstrap-form?
I can use from django.forms.extras.widgets import SelectDateWidget
and get the field to render, but it renders as three stacked items. I want a horizontal display which is the way it renders if I user {{form}}
instead of {{form|bootstrap}}
Anyone know of an elegant (and easy) way to accomplish this?
Sincerely,
Alan Viars
example/app/templates/index.html
(23L)
below demostate how the form looks with bootstrap
I assume that it is "demonstrate".
I am using django-bootstrap-form
in my project with a MultiWidget field which consists of a RadioSelect
and a TextInput
and the modul adds the form-control
automatically to both fields.
Is there any way how to deal with this behavior without editing the module?
It would be great if we could override the default label_cols value on a site-side basis. Here is where the default value is currently hard-coded:
Great idea to keep bootstrap to tags in Django. Might be better than making real BootstrapForm, BootstrapModelForm, etc.
But why limit it to forms only? You could have tags to include Bootstrap CSS, additional JavaScript (required to make topbar etc work).
Catching this deprecation warning when rendering using the template tag.
/bootstrapform/templatetags/bootstrap.py:80: RemovedInDjango110Warning: render() must be called with a dict, not a Context.
return template.render(context)
Hey there,
I really enjoy using django-bootstrap-form in my project. Today I ran into the problem that there were bullet points in front of my checkboxes. I tried several CSS-code that didn't work for me. I found in your example the right solution and was wondering why you don't include this pice of code inside you package? I think that nobody needs the bullets when rendering checkbox forms.
Bye, aronadaal
Love this! Thanks for writing it. Quick thought:
It would be nice to be able to set the size when displaying the fields (either for all or individual). I believe the 2.x syntax is by adding a "span[x]" class to the input element.
http://twitter.github.com/bootstrap/base-css.html#forms
Thanks again!
return render(element, markup_classes)
File "XXXXXXX/lib/python2.7/site-packages/bootstrapform/templatetags/bootstrap.py", line 74, in render
for field in element.visible_fields():
AttributeError: 'SafeText' object has no attribute 'visible_fields'
Here's the script that was used for the test:
from datetime import datetime
from bootstrapform.templatetags.bootstrap import bootstrap
from django import forms
class SomeTestForm(forms.Form):
field_1 = forms.CharField(max_length=20)
field_2 = forms.CharField(max_length=20)
field_3 = forms.CharField(max_length=20)
field_4 = forms.CharField(max_length=20)
field_5 = forms.CharField(max_length=20)
def create_form():
initial = {
'field_1': 'Some random string 1.',
'field_2': 'Some random string 2.',
'field_3': 'Some random string 3.',
'field_4': 'Some random string 4.',
'field_5': 'Some random string 5.'
}
return SomeTestForm(initial=initial)
# Test rendering 1000 forms
forms = [create_form() for f in range(1000)]
# render using django form render
start_time_django_rendering = datetime.utcnow()
for form in forms:
form.as_table()
end_time_django_rendering = datetime.utcnow()
total_django_rendering_time = (end_time_django_rendering - start_time_django_rendering)
print('Total django rendering time: {0}'.format(total_django_rendering_time))
# render using bootstrap form renderer
start_time_bootstrap = datetime.utcnow()
for form in forms:
bootstrap(form)
end_time_bootstrap = datetime.utcnow()
total_bootstrap_time = end_time_bootstrap - start_time_bootstrap
print('Total bootstrap rendering time: {0}'.format(total_bootstrap_time))
Result test runs:
Run 1:
Total django rendering time: 0:00:01.293791
Total bootstrap rendering time: 0:00:06.579422
Run 2:
Total django rendering time: 0:00:01.298067
Total bootstrap rendering time: 0:00:06.548636
Run 3:
Total django rendering time: 0:00:01.304047
Total bootstrap rendering time: 0:00:06.530172
Run 4:
Total django rendering time: 0:00:01.293400
Total bootstrap rendering time: 0:00:06.584375
Run 5:
Total django rendering time: 0:00:01.294149
Total bootstrap rendering time: 0:00:06.550580
I'm finding that when trying to use in-line error message with textfields that django-bootstrap-form is pushing the errors below the text box, which is not the desired functionality in my case. The culprit is an empty span element with class="help-block". When I remove the empty span element, the issue is resolved and the error appears in-line. So I know the source of the problem, but I have no way to fix it since the form is generated for me. Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.