Last active
May 19, 2022 14:45
-
-
Save SilentKernel/220993d6715b1ec4115279f12ef1457a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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