International Telephone Input UI component for Quasar
npm install quasar-ui-q-tel-input

A simple International Telephone Input component for Quasar.
Compatible with Quasar UI v2 and Vue 3.

getCountries().+7701123456 |US | Country that selected by default |FULL | Validation strictness. One of ['NONE', 'LENGTH', 'FULL', 'CUSTOM'] (details below) |[] | Locales to use for country names in dropdown list. First parameter of Intl.DisplayNames constructor |${name} +${callingCode} |false | Toggles searchbar for countries in dropdown |...and props available for QInput.
ts
{
validationStatus: string | undefined // Error code if in error state
country: string | undefined
callingCode: string | undefined // e.g. '7' for KZ
nationalNumber: string | undefined
}
`$3
- These two errors only occur when country is not set yet (e.g. on initial parse):
- INVALID_COUNTRY - when value passed to input is non-international number or has unknown calling code
- NOT_A_NUMBER - when value passed to input is not a phone number (empty or contains invalid characters e.g. letters)- Other errors:
-
TOO_SHORT - when value is too short
- INVALID - when value is not valid
- ANOTHER_COUNTRY - when country in dropdown differs from parsed
Validation
QTelInput validates value depending on the strictness:
- NONE - no validation and highlighting at all
- LENGTH - validate only length
- FULL - validate length and number itself
- CUSTOM - custom validation> Note:
QTelInput has error state, but doesn't show error message.
> You can get error code from validationStatus and set corresponding error message with errorMessage QInput prop.$3
With strictness="CUSTOM" you can pass your own validation function validateFn:
`js
strictness="CUSTOM"
:validate-fn="myValidateFunction"
/>
`Note that
validateFn can return the same value as functions in rules prop for QInput.
`ts
type validateFn = (data: Data, validators: Validators) => boolean | ERROR_CODE | undefinedinterface Data {
number: string
country: string
callingCode: string
nationalNumber: string
}
interface Validators {
number: Function, // Used for validation with strictness="FULL"
length: Function // Used for validation with strictness="LENGTH"
}
`Example:
`js
// Same as 'FULL' but also allows empty input
const validateFn = (data, validators) => {
return !data.nationalNumber ? undefined : validators.number()
}
`
Install
Quasar CLI project
Install the App Extension:
`bash
quasar ext add q-tel-input
`
Quasar CLI will retrieve it from NPM and install the extension.OR:
Create and register a boot file:
`js
import Vue from 'vue'
import Plugin from 'quasar-ui-q-tel-input'
import 'quasar-ui-q-tel-input/dist/index.css'Vue.use(Plugin)
`OR:
`html
`
Vue CLI project
`js
import Vue from 'vue'
import Plugin from 'quasar-ui-q-tel-input'
import 'quasar-ui-q-tel-input/dist/index.css'Vue.use(Plugin)
`OR:
`html
`
UMD variant
Exports window.qTelInput.
Add the following tag(s) after the Quasar ones:
`html
`
If you need the RTL variant of the CSS, then go for the following (instead of the above stylesheet link):
`html
`
Setup
`bash
$ yarn
`
Developing
`bash
start dev in SPA mode
$ yarn devstart dev in UMD mode
$ yarn dev:umdstart dev in SSR mode
$ yarn dev:ssrstart dev in Cordova iOS mode
$ yarn dev:iosstart dev in Cordova Android mode
$ yarn dev:androidstart dev in Electron mode
$ yarn dev:electron
`
Building package
`bash
$ yarn build
`
Adding Testing Components
in the ui/dev/src/pages you can add Vue files to test your component/directive. When using yarn dev to build the UI, any pages in that location will automatically be picked up by dynamic routing and added to the test page.
Adding Assets
If you have a component that has assets, like language or icon-sets, you will need to provide these for UMD. In the ui/build/script.javascript.js file, you will find a couple of commented out commands that call addAssets. Uncomment what you need and add your assets to have them be built and put into the ui/dist` folder.