Reputation: 33625
I'm using django-crispy-forms I want to add an attribute http-prefix
to the outputted domain field, for example like this...
<input type="text" name="domain" http-prefix>
How is this possible? I can see crispy-forms has the ability to add css to a field self.helper.field_class
, but I cannot see where to add an attribute to a field like my example above just http-prefix.
My Form:
class SchemeForm(NgModelFormMixin, forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SchemeForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-lg-3'
self.helper.field_class = 'col-lg-8'
self.helper.layout = Layout(
'name',
'domain',
'slug',
class Meta:
model = Scheme
fields = ('name', 'domain', 'slug')
Upvotes: 0
Views: 387
Reputation: 15519
Simply update the attribute by setting the value to empty string:
def __init__(self, *args, **kwargs):
super(SchemeForm, self).__init__(*args, **kwargs)
#...
self.fields['domain'].widget.attrs['http-prefix'] = ''
Upvotes: 3