Possibility to change nationalMode value

Created on 26 May 2023, over 1 year ago
Updated 11 July 2024, 6 months ago

Problem/Motivation

Element by default returns 'placeholder' value as national phone number. That means it uses local area code to display number. For example number '+49 30 901820' would be shown as '030 901820'.
There was a need of changing 'placeholder' value to international number all the time. To do that we need intl-tel-input library parameter 'nationalMode' to be false. But here its always true.

Steps to reproduce

Use phone_international field, fill international number, for example '+49 30 901820'. Save field and see that place holder shows national number '030 901820', when field value is still '+49 30 901820'.

Proposed resolution

Add attribute to element, for example 'national_number', to change js 'nationalMode' value.

Feature request
Status

Needs work

Version

3.3

Component

Code

Created by

🇱🇹Lithuania ugas19

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

  • Issue created by @ugas19
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Build Successful
  • Status changed to Needs work 6 months ago
  • 🇵🇹Portugal saidatom Lisbon
  • 🇮🇳India nayana_mvr

    The above patch has failed to apply, getting the following error:-

    user phone_international % git apply -v phone_international-change_national_mode-3362902-3_0.patch
    Checking patch js/phone_international.js...
    error: while searching for:
    
            const country = field.getAttribute("data-country");
            const geolocation = parseInt(field.getAttribute("data-geo"));
            const exclude = field.getAttribute("data-exclude");
            const only = field.getAttribute("data-only");
            const preferred = field.getAttribute("data-preferred");
    
    error: patch failed: js/phone_international.js:5
    error: js/phone_international.js: patch does not apply
    Checking patch src/Element/PhoneInternationalElement.php...
    Checking patch src/Plugin/Field/FieldWidget/PhoneInternationalDefaultWidget.php...

    I tried the following steps in Drupal 10.4.x version:-

    1. Created a phone international field in Admin/Configuration/People/Account Settings
    2. Created a new user in Admin/People/Add user with international number +49 30 901820 and saved
    3. When I accessed the user edit page, it is showing national number '030 901820' with country selected i.e., Germany(+49)

    But as per intl-tel-input, it is recommended to leave this option enabled i.e., true, to encourage users to enter their numbers in national format as this is usually more familiar to them and so it creates a better user experience. So instead of adding an option to change nationalMode value, I think it would be better to have an option to show the dial code along with the country code selected which will look like this in the edit page:-

    I have created a ticket for implementing the same https://www.drupal.org/project/phone_international/issues/3460732 📌 Option to enable country dial code in the input field Needs review . Please check if this is useful.

Production build 0.71.5 2024