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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3207818-2.patch | 1.76 KB | init90 |
Comments
Comment #2
init90Comment #3
init90Comment #4
init90Comment #5
saidatomComment #7
saidatomComment #9
dawid_nawrot commented@init90 Thanks a lot for this contribution, it make sense and simplifies things when update of options is reqiuired.