Skip to content

Commit a61701e

Browse files
committed
svelte cmp fix: usePreciseValidation prop instead of strictMode
1 parent cd28ce6 commit a61701e

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

grunt/watch.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ module.exports = function(grunt) {
2727
files: ["vue/src/intl-tel-input/IntlTelInput.vue"],
2828
tasks: "build:vue"
2929
},
30+
svelte: {
31+
files: ["svelte/src/intl-tel-input/IntlTelInput.svelte"],
32+
tasks: "build:svelte"
33+
},
3034
angular: {
3135
files: [
3236
"angular/src/intl-tel-input/angular.tsx",

site/src/docs/svelte_component.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ Default: `null`
9696

9797
A handler to be called when the number validity changes, e.g. to true/false. It will be passed the new isValid boolean.
9898

99+
###### usePreciseValidation
100+
Type: `Boolean`
101+
Default: `false`
102+
103+
By default, we use `isValidNumber` for validation, but if you'd rather use `isValidNumberPrecise`, you can set this to `true`.
104+
99105
## Accessing Instance Methods
100106

101107
You can access all of the plugin's [instance methods](/docs/methods#instance-methods) (`setNumber`, `setCountry`, `setPlaceholderNumberType`, etc.) by passing a ref into the IntlTelInput component (using `bind:this`), and then calling the `getInstance()` method, e.g. `ref.getInstance().setNumber(...);`. See the [Set Number demo](https://github.com/jackocnr/intl-tel-input/blob/master/svelte/demo/set-number/App.svelte) for a full example. You can also access the input DOM element via: `ref.getInput()`.

svelte/src/intl-tel-input/IntlTelInput.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
disabled = false,
1010
inputProps = {},
1111
options = {},
12+
usePreciseValidation = false,
1213
value = "",
1314
onChangeNumber,
1415
onChangeCountry,
@@ -19,6 +20,7 @@
1920
inputProps?: Record<string, unknown>;
2021
options?: SomeOptions;
2122
value?: string;
23+
usePreciseValidation?: boolean;
2224
onChangeNumber?: (number: string) => void;
2325
onChangeCountry?: (country: string) => void;
2426
onChangeValidity?: (valid: boolean) => void;
@@ -34,7 +36,7 @@
3436
// Validation helper
3537
const isValid = (): boolean | null => {
3638
if (!instance) return null;
37-
return options.strictMode
39+
return usePreciseValidation
3840
? instance.isValidNumberPrecise()
3941
: instance.isValidNumber();
4042
};

svelte/src/intl-tel-input/IntlTelInputWithUtils.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import intlTelInput from "./intlTelInputWithUtils";
1010
disabled = false,
1111
inputProps = {},
1212
options = {},
13+
usePreciseValidation = false,
1314
value = "",
1415
onChangeNumber,
1516
onChangeCountry,
@@ -20,6 +21,7 @@ import intlTelInput from "./intlTelInputWithUtils";
2021
inputProps?: Record<string, unknown>;
2122
options?: SomeOptions;
2223
value?: string;
24+
usePreciseValidation?: boolean;
2325
onChangeNumber?: (number: string) => void;
2426
onChangeCountry?: (country: string) => void;
2527
onChangeValidity?: (valid: boolean) => void;
@@ -35,7 +37,7 @@ import intlTelInput from "./intlTelInputWithUtils";
3537
// Validation helper
3638
const isValid = (): boolean | null => {
3739
if (!instance) return null;
38-
return options.strictMode
40+
return usePreciseValidation
3941
? instance.isValidNumberPrecise()
4042
: instance.isValidNumber();
4143
};

0 commit comments

Comments
 (0)