|
36 | 36 | <input |
37 | 37 | ref="input" |
38 | 38 | v-model="phone" |
39 | | - :placeholder="placeholder" |
| 39 | + :placeholder="parsedPlaceholder" |
40 | 40 | :disabled="disabled" |
41 | 41 | :required="required" |
42 | 42 | :autocomplete="autocomplete" |
@@ -284,18 +284,33 @@ export default { |
284 | 284 | type: Boolean, |
285 | 285 | default: false, |
286 | 286 | }, |
| 287 | + dynamicPlaceholder: { |
| 288 | + type: Boolean, |
| 289 | + default: false, |
| 290 | + }, |
287 | 291 | }, |
288 | 292 | data() { |
289 | 293 | return { |
290 | 294 | phone: '', |
291 | 295 | activeCountry: { iso2: '' }, |
292 | 296 | open: false, |
| 297 | + finishMounted: false, |
293 | 298 | selectedIndex: null, |
294 | 299 | typeToFindInput: '', |
295 | 300 | typeToFindTimer: null, |
296 | 301 | }; |
297 | 302 | }, |
298 | 303 | computed: { |
| 304 | + parsedPlaceholder() { |
| 305 | + if (!this.finishMounted) { |
| 306 | + return ''; |
| 307 | + } |
| 308 | + if (this.dynamicPlaceholder) { |
| 309 | + const mode = this.mode || 'international'; |
| 310 | + return PhoneNumber.getExample(this.activeCountry.iso2, 'mobile').getNumber(mode); |
| 311 | + } |
| 312 | + return this.placeholder; |
| 313 | + }, |
299 | 314 | parsedMode() { |
300 | 315 | if (this.mode) { |
301 | 316 | if (!['international', 'national'].includes(this.mode)) { |
@@ -379,16 +394,21 @@ export default { |
379 | 394 | }, |
380 | 395 | }, |
381 | 396 | mounted() { |
382 | | - this.initializeCountry().then(() => { |
383 | | - if (!this.phone |
| 397 | + this.initializeCountry() |
| 398 | + .then(() => { |
| 399 | + if (!this.phone |
384 | 400 | && this.inputOptions |
385 | 401 | && this.inputOptions.showDialCode |
386 | | - && this.activeCountry) { |
387 | | - this.phone = `+${this.activeCountry.dialCode}`; |
388 | | - } |
389 | | - this.$emit('validate', this.phoneObject); |
390 | | - this.$emit('onValidate', this.phoneObject); // Deprecated |
391 | | - }).catch(console.error); // eslint-disable-line |
| 402 | + && this.activeCountry.dialCode) { |
| 403 | + this.phone = `+${this.activeCountry.dialCode}`; |
| 404 | + } |
| 405 | + this.$emit('validate', this.phoneObject); |
| 406 | + this.$emit('onValidate', this.phoneObject); // Deprecated |
| 407 | + }) |
| 408 | + .catch(console.error) |
| 409 | + .finally(() => { |
| 410 | + this.finishMounted = true; |
| 411 | + }); |
392 | 412 | }, |
393 | 413 | created() { |
394 | 414 | if (this.value) { |
|
0 commit comments