I want to use bootstrap tagsinput feature in my form. For that I need to add data-role="tagsinput"
. Is there a way that I can include this thing in my field?
Asked
Active
Viewed 674 times
0

mariodev
- 13,928
- 3
- 49
- 61

Sudhanshu Mishra
- 2,024
- 1
- 22
- 40
-
2http://stackoverflow.com/questions/2902008/django-how-do-i-add-arbitrary-html-attributes-to-input-fields-on-a-form – mariodev Dec 15 '13 at 09:38
2 Answers
1
You can use the attrs
argument on your widget, for example in a ModelForm:
class FooModelForm(forms.ModelForm):
class Meta:
model = Foo
widgets = {
'yourfield': forms.TextInput(attrs={'data-role': 'tagsinput'})
}

sk1p
- 6,645
- 30
- 35
1
You can use django-crispy-forms (https://github.com/maraujop/django-crispy-forms). It has bootstrap support. You can manage attributes and css classes very easy:
https://django-crispy-forms.readthedocs.org/en/latest/layouts.html
Read "Layout objects attributes"
I highly recommend to use this project

Konstantin Kovrizhnykh
- 191
- 2