Skip to content

Instantly share code, notes, and snippets.

@SilentKernel
Last active May 19, 2022 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SilentKernel/220993d6715b1ec4115279f12ef1457a to your computer and use it in GitHub Desktop.
Save SilentKernel/220993d6715b1ec4115279f12ef1457a to your computer and use it in GitHub Desktop.
import {Controller} from '@hotwired/stimulus'
import intlTelInput from 'intl-tel-input';
export default class extends Controller {
static targets = ['input'];
static values = {
currentNumber: String
};
connect() {
let localizedCountries = {};
this.intlInput = intlTelInput(this.inputTarget, {
utilsScript: '/static/intl-tel-input-utils.js',
hiddenInput: 'phone',
preferredCountries: ['fr', 'lu', 'be', 'de', 'ch'],
localizedCountries
});
if (this.currentNumberValue !== '') {
this.intlInput.setNumber(this.currentNumberValue)
}
}
disconnect() {
this.intlInput.destroy();
super.disconnect();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment