python - How to add own class into field if this field is not valid? -


how add own class field if field not valid?

for example if field not valid add class="invalid"

forms:

class myform(forms.form):     myfield = forms.charfield() 

template:

{{ form.myfield }} 

edited answer more precisely.

if want specify class error or required fields:

class myform(form):     error_css_class = 'error' #here can set 'invalid'     required_css_class = 'required' 

ref: https://docs.djangoproject.com/en/1.6/ref/forms/api/

you can change class 1 field with:

myfield= forms.charfield(attrs={'class': 'myclass'}) 

ref: https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.widget.attrs


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -