Phone International field clears input value on every keystroke in Drupal 11

Created on 10 September 2025, 11 days ago

When using the Phone International field on a Drupal 11.2 site, the phone input does not allow entering numbers.
Each digit typed into the field is immediately cleared, as if pressing the delete key.

Steps to reproduce:

  • Install Drupal 11.2 with the phone_international v4.x module enabled.
  • Add a user field of type Phone International.
  • Edit a user and try to type a phone number.

Notice that every keystroke clears the input, so no number can be entered.

Debugging details:

Manually setting the value in the console (input.value = '12345') persists correctly, so the clearing only happens during typing.

Adding a listener trace showed that the module’s JS behavior forces field.value('') whenever iti.getNumber() returns an empty string, effectively erasing user input.

Expected behavior:

The field should allow users to type normally, and the number formatting/validation should only update the value if it is non-empty and valid.

Proposed solution:

Update the behavior so that the input value is only replaced when iti.getNumber() returns a valid number, instead of overwriting it with an empty string during typing.
Example:

          field.addEventListener('keyup', () => {
            var number = iti.getNumber();
            if (number) {
              field.val(number);
            }
          });
🐛 Bug report
Status

Needs review

Version

4.0

Component

Code

Created by

🇪🇸Spain saganakat

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024