Skip to content
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

Set PhoneNumberInternationalFallbackWidget input_type to tel #521

Merged
merged 1 commit into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions phonenumber_field/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class PhoneNumberInternationalFallbackWidget(TextInput):
an international number will fall back to international format
"""

input_type = "tel"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change, but I wonder if it will break some peoples code/styling. I think it needs to be mentioned in release notes and maybe even with a bigger version bump 🤔 .

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a good idea. I’ll add it to the 7.0.0 with #520 (which may also introduce a small BC breakage).


def __init__(self, region=None, attrs=None):
if region is None:
region = getattr(settings, "PHONENUMBER_DEFAULT_REGION", None)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ def test_fallback_widget_switches_between_national_and_international(self):
de_widget = PhoneNumberInternationalFallbackWidget(region="DE")
self.assertHTMLEqual(
gb_widget.render("number", number),
'<input name="number" type="text" value="01606 75178" />',
'<input name="number" type="tel" value="01606 75178" />',
)
self.assertHTMLEqual(
de_widget.render("number", number),
'<input name="number" type="text" value="+44 1606 75178" />',
'<input name="number" type="tel" value="+44 1606 75178" />',
)

# If there's been a validation error, the value should be included verbatim
self.assertHTMLEqual(
gb_widget.render("number", "error"),
'<input name="number" type="text" value="error" />',
'<input name="number" type="tel" value="error" />',
)