Define css class in django Forms

前端 未结 13 840
南旧
南旧 2020-11-27 10:11

Assume I have a form

class SampleClass(forms.Form):
    name = forms.CharField(max_length=30)
    age = forms.IntegerField()
    django_hacker = forms.Boolea         


        
13条回答
  •  伪装坚强ぢ
    2020-11-27 10:43

    Here is a variation on the above which will give all fields the same class (e.g. jquery nice rounded corners).

      # Simple way to assign css class to every field
      def __init__(self, *args, **kwargs):
        super(TranslatedPageForm, self).__init__(*args, **kwargs)
        for myField in self.fields:
          self.fields[myField].widget.attrs['class'] = 'ui-state-default ui-corner-all'
    

提交回复
热议问题