svelte-tags-input icon indicating copy to clipboard operation
svelte-tags-input copied to clipboard

Support binding value

Open etclub opened this issue 3 years ago • 6 comments

I hope bind:value is supported.

etclub avatar Feb 03 '21 09:02 etclub

@etclub There's no support for it here it didn't work

gabrieldejesus avatar Sep 01 '21 12:09 gabrieldejesus

Any prevision @agustinl ?

gabrieldejesus avatar Sep 01 '21 12:09 gabrieldejesus

It would be great if it supported bind:value directly.

Until then, you can work around it with something like:

function handleTags(event) {
  $form.tags = event.detail.tags;
}

...

<Tags
  on:tags={handleTags}
  ...
/>

I'm using above successfully with svelte-forms-lib.

mstibbard avatar Sep 03 '21 02:09 mstibbard

Thank you @mstibbard I'm going to test something in this sense around here until there's this feature in the package

gabrieldejesus avatar Sep 03 '21 08:09 gabrieldejesus

Hi @etclub @gabrieldejesus @mstibbard

If I add bind:value to the input on <Tags> component, you will see the tags added for the client on the input. The idea is add a tag and make the input blank to add another one.

You can use the following function:

<script>
let tag = "";

function handleTags(event) {
     tag = event.detail.tags;
}
</script>

<Tags
     on:tags={handleTags}
/>

Let me know if I can provide more help.

agustinl avatar Oct 12 '21 22:10 agustinl

@agustinl I think something like this handleTags function could be moved inside the Tags component to update a values prop on the component reactively. Then the component's parent could use a bind:values directive to get access to that reactive list of tags. It doesn't need to bind directly to an HTML value attribute. This would definitely be a nice & expected feature for a Svelte input component, and it would make integration with form libraries like svelte-forms-lib which use bindings for core functionality more straightforward and consistent!

addiebarron avatar Mar 28 '22 19:03 addiebarron

with new Sevelt Form Actions (https://kit.svelte.dev/docs/form-actions), we may not be able to use libs like svelte-forms-lib it is hard to use without setting from input value to leverage progressively enhanced forms.

xmlking avatar Nov 10 '22 18:11 xmlking

a workaround may be to dispatch Custom Event with target, sothat handleTags method can set the value to target's form input element

https://svelte.dev/repl/c93cbf99a8ca4f44912e662a8e3cbef7?version=3.37.0

xmlking avatar Nov 10 '22 18:11 xmlking

Hello everyone! I created a PR with support for binding tags.

Will be very helpful your help to test if all works fine. From my side I saw all fine, but 4 eyes see better than 2

thanks for the patience 💪

agustinl avatar Nov 19 '22 15:11 agustinl

I tested. it worked as expected.

https://github.com/xmlking/svelte-starter-kit/commit/9f52ad68b870a5a4a454186e2a2a1943520ebe86

xmlking avatar Nov 20 '22 00:11 xmlking

@agustinl can you add default values or types to all exported values as I changed here: https://github.com/xmlking/svelte-starter-kit/blob/main/src/lib/components/Tags.svelte

this helps to make VSCode not to show imports RED image

xmlking avatar Nov 20 '22 01:11 xmlking

Hi @xmlking I will add types support in other branch. Thanks for your help!

agustinl avatar Dec 08 '22 22:12 agustinl