0

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')

1 Answer 1

3

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'] = ''
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.