Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Svelte form data is lost when components are hidden

I am using Svelte and Flowbite components (basically a tailwind-css wrapper) to create a form. I put some of my form inputs into an accordion element which can be toggled to display or not. Now I notice when I fill in the form details, then hide the component, all input data is lost because all elements are actually removed from the DOM. This is catastrophic for me, is there some way to tell svelte not to do this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can’t if you not the author and the components do not offer properties to change the behavior. They likely use {#if} internally which add/removes the contents rather than using classes.

As a consumer, you can use bind:property (e.g. on value, checked, etc.) on the inputs of the form to locally store the values, that way, when the form is recreated it will be populated with said values again.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading