VeryApt / django-phone-field

Lightweight model and form field for phone numbers in Django
GNU General Public License v3.0
52 stars 13 forks source link

Model field using PhoneField is not recognized in a ModelForm #10

Closed flvyu closed 4 years ago

flvyu commented 4 years ago

I have created a model with a phone_number field like the following:

phone_number = PhoneField(blank=False, help_text='Contact Number')

However when I use this model to create a ModelForm, the form has an error when is_valid is called saying that phone number is required even though the data is passed to the request. All the other fields that are required work fine.

Ex:

class ApplicationForm(ModelForm):
    class Meta:
        model = Application
        fields = ['first_name', 'last_name', 'email', 'phone_number']

Environment: django 3.0 Python 3

va-andrew commented 4 years ago

I created a ModelForm view along the lines you mention: b17e83e8372ac509bf2bf61ba452aed0d1e1e17f

However, I am unable to replicate this with Django 3.0. Can you create a fork with an example?

flvyu commented 4 years ago

I also could not reproduce it using the fork I made of the branch. However, still having the issue on the other application.

va-andrew commented 4 years ago

Ah okay. I'm closing this issue for now, feel free to reopen if you can reproduce it with our test project.

Radilx commented 3 years ago

Just wanted to say -- I was having similar issues. You have to use {{ form.phone }}, you can't try to do things like constructing your own custom form and extracting {{ form.phone.id_for_label}}. My client page was sending phone in the post request instead of phone_0 and phone_1 like the ModelForm was expecting.