Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the value from outside #206

Open
HoekWax opened this issue Sep 26, 2023 · 10 comments
Open

Update the value from outside #206

HoekWax opened this issue Sep 26, 2023 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@HoekWax
Copy link

HoekWax commented Sep 26, 2023

Hello,

Is there away to update the value from the outside ?

I can reset it but I don't know how to change it to another value.
For now I unmount the component for 1ms and mount it again with a new default value.

Thanks

@gyurielf
Copy link
Owner

At this point you can't do this via the component, because the point was to sanitize and standardize the entered user input.
What is the use case for changing value from outside after the mount ?

@HoekWax
Copy link
Author

HoekWax commented Sep 27, 2023

Oh ok, well it making it disappear and appear again works, i set up a second placeholder input right behind so that there the user still sees an input during the unmount/remount of the input.

I am making an autocomplete, when the user starts typing the number, I show under the input all the phone numbers that could match, if the user click on one, I fill the input with the number.

You can close this if you don't plan on implementing it

@gyurielf gyurielf self-assigned this Sep 27, 2023
@gyurielf gyurielf added the enhancement New feature or request label Sep 28, 2023
@gyurielf
Copy link
Owner

gyurielf commented Oct 1, 2023

I'll investigate that, how possible to implement.

@bosticka
Copy link

bosticka commented Oct 8, 2023

If you pass in an id to the TelInput component like so:

	<TelInput
		bind:country={selectedCountry}
		bind:detailedValue
		bind:value
		bind:valid
                id={e164Input_id}
		{options}
         />

Then you can grab the reference to the underlying input and set the value there like so:

        let el = document.getElementById(e164Input_id);
        el.value = your_value;

This is my current workaround for changing the value of an already mounted svelte-tel-input component.

The only downside for me is it doesn't format the value you set it to.

Could you possible export the handleParsePhoneNumber function so we could bind to the TelInput component and call this whenever we need to programmatically set the value?

@gyurielf
Copy link
Owner

gyurielf commented Oct 8, 2023

If you pass in an id to the TelInput component like so:

	<TelInput
		bind:country={selectedCountry}
		bind:detailedValue
		bind:value
		bind:valid
                id={e164Input_id}
		{options}
         />

Then you can grab the reference to the underlying input and set the value there like so:

        let el = document.getElementById(e164Input_id);
        el.value = your_value;

This is my current workaround for changing the value of an already mounted svelte-tel-input component.

The only downside for me is it doesn't format the value you set it to.

Could you possible export the handleParsePhoneNumber function so we could bind to the TelInput component and call this whenever we need to programmatically set the value?

Hey!

Yep, that was my first thought too, just have to test it.

I'll make a PR soon.

@ramonvictorn
Copy link

I also would like to have this, for my use case is simple:
I'm using sveltekit with stream requests, so, the page is loaded before I have the data and also the default values for the inputs.

So In the initial render I don't have the values and after some time the request is finished with the values. I'm using SPA mode.

Why not is possible to just update the values, even when using bind?

@gyurielf
Copy link
Owner

Hey!
I'm pretty busy with working, but the PR is on the way which solve this issue.
(this part is actually done, but that PR contains breaking changes)
Binding is not possible because the value inside the input is not exactly the same with the value of the component.

@zulfiqarlaili
Copy link

Oh ok, well it making it disappear and appear again works, i set up a second placeholder input right behind so that there the user still sees an input during the unmount/remount of the input.

I am making an autocomplete, when the user starts typing the number, I show under the input all the phone numbers that could match, if the user click on one, I fill the input with the number.

You can close this if you don't plan on implementing it

Hey, thank you for the suggestion. I'm applying this to my project too. May God bless you in any way possible.

@bosticka
Copy link

bosticka commented Jan 3, 2024

Are you still planning on making handleParsePhoneNumber available as a component method?

Thanks!

@gyurielf
Copy link
Owner

gyurielf commented Jan 4, 2024

Are you still planning on making handleParsePhoneNumber available as a component method?

Thanks!

Hey!
I was on holiday and in the new year project starts like hell. So I'm pretty busy.
This part is also done.
There will be an update method which will be exposed, to handle this.

The main reason for that PR is so late is the national number handling and parsing...
maybe the international format will be the default and only format. We'll see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants