dyaliCode / svelte-formly

Generator dynamic forms for Svelte JS
https://svelte.formly-js.com
MIT License
253 stars 29 forks source link

How to make form more reactive #66

Closed KelvinSan closed 2 months ago

KelvinSan commented 6 months ago

Currently I a modal that render form via API call, however when I change the contents of fields via API response the form does not change. How can I make this possible ?

WeaveMN commented 5 months ago

Hey @KelvinSan, I was running into the same issue in my app swapping between different views with different field configurations and/or field values. The quick fix I found was to use the Svelte "key" tag to force a re-render of the entire form.

Example (I have unique form names on each view but putting "fields" in as the key should work as well):

    {#key form_name}
      <Formly
        {form_name}
        {fields}
        btnReset={{"text":"","classes":['invisible']}}
        btnSubmit={{"text":``,"classes":['invisible']}} 
        on:update={formUpdated}
        realtime={true}
      />
    {/key}

Hope that helps you and others.