When re-rendering form with errors, the user input for phone number is cleared. But only when the default region was selected. When user selected a different region than the one specified in PHONENUMBER_DEFAULT_REGION, his input persists.
Entered phone number is not present even if it was valid.
At first I was certain the error lied somewhere in my code, but after building a bare bone form and view I concluded it has to be a bug. FYI I have just upgraded to django 4.1 (from 3.2) and all other packages.
I'm currently using:
Python 3.10
Django 4.1
django-phonenumber-field 6.3.0 (tried also dev version, which solves ignoring required=True on field at least)
My bare-bone example:
Settings.py
PHONENUMBER_DEFAULT_REGION = 'SI'
Forms.py
from phonenumber_field.formfields import PhoneNumberField
from phonenumber_field.widgets import PhoneNumberPrefixWidget
class TestForm(forms.Form):
name = forms.CharField(max_length=200, min_length=3) # Just here for triggering an invalid form
tel = PhoneNumberField(required=False, widget=PhoneNumberPrefixWidget())
Views.py
from .forms import TestForm
class TestFormView(FormView):
form_class= TestForm
template_name="test_form.html"
When re-rendering form with errors, the user input for phone number is cleared. But only when the default region was selected. When user selected a different region than the one specified in PHONENUMBER_DEFAULT_REGION, his input persists. Entered phone number is not present even if it was valid.
At first I was certain the error lied somewhere in my code, but after building a bare bone form and view I concluded it has to be a bug. FYI I have just upgraded to django 4.1 (from 3.2) and all other packages.
I'm currently using:
My bare-bone example:
Settings.py
PHONENUMBER_DEFAULT_REGION = 'SI'
Forms.py
Views.py
Html