New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatting being lost #539
Comments
Can you precise where the format is being lost? Is that in your console, in the HTML generated by your template, in your HTML input values? |
I have a unittest that tests entering an international number, like In essence, the default behavior of the field supported both formats in the same field, and this test passed. After upgrading from version I imagine the only way this was possible is if Is it no longer possible to store US and international phone numbers in the same field anymore? If so, that's your design call, but I'll need to fork the project to maintain the previous functionality for my clients, as a ton of people store both formats in the same field. |
I’m confused. Both >>> import phonenumbers
>>> x = phonenumbers.parse("+18001234567")
>>> phonenumbers.is_valid_number(x)
False The library treats invalid phone numbers as just an def test_invalid_number(self):
invalid_numbers = ["+18001234567", "800-123-4567"]
widget = RegionalPhoneNumberWidget()
for invalid_number in invalid_numbers:
number = PhoneNumber.from_string(invalid_number, region="US")
self.assertHTMLEqual(
widget.render("number", number),
f'<input name="number" type="tel" value="{invalid_number}" />',
) Without customization, the admin should be using that widget, thus your tests should pass, unless other customizations have been applied? For valid phone numbers, the library by default will:
Here’s the widget implementing the behavior described above: django-phonenumber-field/phonenumber_field/widgets.py Lines 125 to 158 in 87d113e
|
Finally got some time to look at your report in a project. Indeed, the That’s why the phone numbers are displayed in E164 and not in the configured region. I’ll try to think of a way to use the @admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
PhoneNumberField: {"widget": widgets.RegionalPhoneNumberWidget}
} |
I’ve given this matter some thoughts. I believe we should stick to the What do you think of documenting the above trick ( |
I recently upgraded to
django-phonenumber-field[phonenumbers]==7.0.0
and now all my phone numbers, previously formatted like(800) 123-4567
, are being reformatted as+18001234567
.Do you know why this is?
Is there a new flag or formatting template I should set to maintain my preferred format?
The text was updated successfully, but these errors were encountered: