aerni / statamic-livewire-forms

Supercharge your Statamic forms with Livewire
https://statamic.com/addons/aerni/livewire-forms
Other
28 stars 2 forks source link

Add wire:key preventing conditional field swap #24

Closed godismyjudge95 closed 1 year ago

godismyjudge95 commented 1 year ago

Ran into a bug on a project where certain fields (in my case the text area and captcha fields) would be replacing each other's html when conditions were parsed.


Steps to reproduce:

Result:

The captcha field disappears but the captcha itself appears in place of the text area field.

Expected:

The text input field should show and hide based on the select box value while the text area and captcha fields should remain untouched.


Solution:

This is a sometimes random bug with how Livewire parses differences in a loop of html items. Sometimes it cannot tell where the original html should go. The solution is to add wire:key with a unique key (I used the field handle) to the individual items (in this case the field wrappers).

I guess an argument could be made to use the field ID instead of the handle as that might be more unique? For me the handle is working fine.

aerni commented 1 year ago

This is gold. Thanks!