Problem/Motivation

At the moment we pass settings into the library from the widget settings and for most cases, it's enough. But sometimes need to specify more specific options and for that will be good to have the possibility to alter options.

In my case need to alter the placeholder number for specific countries.

Proposed resolution

Allow to alter options from the JS side. To implement it add method alterPhoneLibraryOptions in module and call it from custom JS code when need to alter/add options.

As example:

 Drupal.behaviors.CustomModule = {
    attach: function (context, settings) {
      // Alter phone library options.
      if (Drupal.behaviors.PhoneInternational) {
        Drupal.behaviors.PhoneInternational.alterPhoneLibraryOptions = function(field, options) {
          options.customPlaceholder = function (placeholder, code) {
            // Change swiss number placeholder.
            if (code.iso2 && code.iso2 === 'ch') {
              return '78 123 45 67';
            }

            return placeholder;
          }
        };
      }
    }
  };

Remaining tasks

Determine if such stuff really needed and approach to implement it.

CommentFileSizeAuthor
#2 3207818-2.patch1.76 KBinit90

Comments

init90 created an issue. See original summary.

init90’s picture

StatusFileSize
new1.76 KB
init90’s picture

Issue summary: View changes
init90’s picture

Issue summary: View changes
saidatom’s picture

Status: Active » Needs review

  • saidatom committed 710574c on 3.x authored by init90
    Issue #3207818 by init90: Allow to alter phone library options
    
saidatom’s picture

Version: 3.0.0 » 3.x-dev
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

dawid_nawrot’s picture

@init90 Thanks a lot for this contribution, it make sense and simplifies things when update of options is reqiuired.