svelte-formly icon indicating copy to clipboard operation
svelte-formly copied to clipboard

How to make form more reactive

Open KelvinSan opened this issue 1 year ago • 1 comments

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 ?

KelvinSan avatar Apr 28 '24 16:04 KelvinSan

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.

WeaveMN avatar Jun 05 '24 01:06 WeaveMN