[Answered ]-Django forms: not adding attributes

1๐Ÿ‘

โœ…

I think, you already specified the fields name and surname in the class itself, so you should use inline widgets not Meta widgets, as they are used for overriding default widgets, so:


class AuthorForm(ModelForm):

    name = forms.CharField(validators=[isStandardized],widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Name of an author'}))
    surname = forms.CharField(validators=[isStandardized],widget=forms.TextInput(attrs={'class':'form-control','placeholder':'surname of an author' }))

    class Meta:
      model   = SearchStats
      fields  = ['name', 'surname', 'author_id', 'amount']

      widgets = {
          'author_id': forms.TextInput(attrs={'type':'hidden'}),
          'amount': forms.TextInput(attrs={'type':'hidden'})
      }
๐Ÿ‘คSunderam Dubey

Leave a comment