diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index 7b5ee751b..4882402b5 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -28,7 +28,10 @@ export function uiFieldText(field, context) { if (field.type === 'tel') { fileFetcher.get('phone_formats') - .then(function(d) { _phoneFormats = d; }) + .then(function(d) { + _phoneFormats = d; + updatePhonePlaceholder(); + }) .catch(function() { /* ignore */ }); } @@ -67,13 +70,7 @@ export function uiFieldText(field, context) { if (field.type === 'tel') { - var extent = combinedEntityExtent(); - var countryCode = extent && countryCoder.iso1A2Code(extent.center()); - var format = countryCode && _phoneFormats[countryCode.toLowerCase()]; - if (format) { - wrap.selectAll('input') - .attr('placeholder', format); - } + updatePhonePlaceholder(); } else if (field.type === 'number') { var rtl = (localizer.textDirection() === 'rtl'); @@ -136,6 +133,16 @@ export function uiFieldText(field, context) { } + function updatePhonePlaceholder() { + if (input.empty() || !Object.keys(_phoneFormats).length) return; + + var extent = combinedEntityExtent(); + var countryCode = extent && countryCoder.iso1A2Code(extent.center()); + var format = countryCode && _phoneFormats[countryCode.toLowerCase()]; + if (format) input.attr('placeholder', format); + } + + function validIdentifierValueForLink() { if (field.type === 'identifier' && field.pattern) { var value = utilGetSetValue(input).trim().split(';')[0];