Added label display control
added feature to hide label or not. example: {{ field|bootstrap:False}}
I'm really struggling with this exact same issue right now. In essence, label tags without an value are getting rendered, messing with the alignment of my page.
What are the chances we include this in the official release?
depends on the repo owner. You can still fork my version for now.
Hi @zoner14 I will get this pull request merged and release tomorrow.
I just get back from release a new product of my company.
This is actually my first time using Github. I'm shocked how easy this was. Thank you so much! I really didn't want to have to hack together my own solution such that it differed from the standard release.
@diopib @zoner14
Why not just turn label off by setting it in Form?
Like this
field = forms.CharField(label="")
though ModelForm will be a little bit more complex
@tzangms
I think you shouldn't have to change basic form data...
Just found it would be cleaner to manage it from the template (better if you have complex templates with many conditional statements etc.) But maybe the argument passing can be improved.
@diopib
In Django 1.6, it allows you to override labels in ModelForm, like this
class AuthorForm(ModelForm):
class Meta:
model = Author
labels = {
'field_name: "",
}
I think it's the way that Django works, settings things up in Form, but not to increase the complexity in template.
if you turn of label in Form/ModelForm, you can use just one line in template.
{{ form|bootstrap }}
but seperate every fields into template, and turn one field's label off.
@tzangms I think it all depends on what you want to do, how you want to do it or what django version you're working with. in my case I needed to handle it in the template, that's why I made those changes... Feel free to accept/reject the pull request (currently using my forked version though). But thanks for this app, the idea is great and it's very well thought!
So I actually had first tried setting the label equal to null, and this actually does not work. The API still renders the label.
Here is what one of my form fields looks like:
username = forms.CharField(max_length = 30,
label = '',
widget=forms.TextInput(attrs = {'placeholder': 'Username'})
)
and here is how it renders in HTML after calling {{ form|bootstrap}} hmmmm looks like github filters out my html!
Suffice to say, the label renders like this:< label class="control-label " for="id_username">
Still thinking that changes have to be made on your app, you shouldn't have to "tweak" a django form to achieve that. You should manage the display on the template, not elsewhere (good practice). Thanks all.