[Django]-Django simple form "object has no attribute 'is_hidden'"

0👍

You assign the form field forms.IntegerField to "widget" which is wrong:

class ContactForm(forms.Form):
    # ...                               # Wrong
    phone = forms.CharField(widget=forms.IntegerField)
    # ...

So, instead, you need to assign the widget forms.NumberInput to "widget" which is correct:

class ContactForm(forms.Form):
    # ...                               # Correct
    phone = forms.CharField(widget=forms.NumberInput)
    # ...

6👍

forms.IntegerField is not a widget but a field type on form.

What you need is a forms.NumberInput

phone = forms.CharField(widget=forms.NumberInput)  
👤AKS

1👍

You can use

phone = forms.CharField(widget=forms.TextInput(
      attrs={
          'type' : 'number',
          'class' : 'your_class'
      }))

Leave a comment