django-vies icon indicating copy to clipboard operation
django-vies copied to clipboard

How to change form?

Open VivienGiraud opened this issue 6 years ago • 4 comments

How do I change entry class of VATINField ? This doesn't works vat_number = VATINField(validators=[VATINValidator(verify=True, validate=True)], attrs={"class": "form-control"})

VivienGiraud avatar Feb 03 '19 21:02 VivienGiraud

Hi @VivienGiraud could you give me a bit more context here? I am afraid I can't follow you.

codingjoe avatar Feb 04 '19 07:02 codingjoe

Hi @codingjoe , I can pass html class to forms.py to insert it during forms generation like : name = forms.CharField( max_length=1024, label=_("Name"), required=True, initial=TrideaBillingAddress.name, widget=forms.TextInput( attrs={ "class": "form-control", "placeholder": _("Last Name First Name"), } ), )

How can I do the same using a VATINField field in forms.py ?

VivienGiraud avatar Feb 04 '19 14:02 VivienGiraud

For example email is set like that on our code :

    email = forms.EmailField(
        max_length=254,
        label=_("Email"),
        required=True,
        widget=forms.EmailInput(
            attrs={
                "class": "form-control",
                "placeholder": _("EmailAddress"),
            }
        ),
    )

I would like to do the same on VATField, adding widget attrs to change placeholder or class.

VivienGiraud avatar Feb 06 '19 12:02 VivienGiraud

Hi @VivienGiraud this is a good point, currently you can't change the placeholder, at least not without overriding the VATINWidget. It might make sense to forward this attribute to the text input.

Best -Johannes

codingjoe avatar Feb 08 '19 09:02 codingjoe