Thursday, 15 July 2010

How do I correctly add html attributes to Django form widget -



How do I correctly add html attributes to Django form widget -

i trying utilize parsley.js validation in django project. @ step trying add together necessary parsley attributes form fields. correct, told need pass attributes widget in existing form field.

email = forms.emailfield(widget=forms.textinput(attrs=dict(attrs_dict, maxlength=75)),label=_("email"))

my question how correctly pass attributes form widget can validate form field parsley.js? took stab @ below, know it's incorrect.

email = forms.emailfield(widget=forms.textinput(attrs=dict(attrs_dict, maxlength=75, data-required="true", data-trigger="keyup")), label=_("email"))

overriding __init__ function in form class may best option...

class yourclass(modelform): def __init__(self, *args, **kwargs): self.fields['yourfield'].widget.attrs.update({'yourattribute': 'yourattributevalue'})

django django-forms

No comments:

Post a Comment