New Metronic Docs!Added Integration Docs with Starter Kits Apps for Laravel, Laravel Livewire, Angular, Vue, Symfony, Blazor Server, Django & Flask & more
Browse Docs

How to use KTUI accordion with Livewire and Forms?


I am using the KTUI accordion https://ktui.io/docs/accordion

When I put a form inside the accordion and use livewire, then livewire refreshes the page once I make a change in the select and the accordion looses its active state. How can I fix that?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Hi Adam Nielsen

Sorry for the delay. The cleanest solution is to use Livewire's wire:ignore.self directive on the accordion container. This tells Livewire to ignore DOM changes within that element, preserving the accordion's state:

<div data-kt-accordion="true" class="kt-accordion" wire:ignore.self>
<div data-kt-accordion-item="true" class="kt-accordion-item">
<button

data-kt-accordion-toggle="true"
aria-controls="accordion_content_1"
class="kt-accordion-toggle"
>
<span class="kt-accordion-title">Form Section</span>
<span aria-hidden="true" class="kt-accordion-indicator">
<!-- Your indicator icons -->
</span>
</button>
<div
class="kt-accordion-content hidden"
aria-labelledby="accordion_toggle_1"

>
<div class="kt-accordion-wrapper">
<!-- Your form content here -->
<select wire:model="yourProperty">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</div>
</div>
</div>
</div>



Okay I found a solution, I have to manage the classes `active` and `hidden` via the livewire component manually. If there is a better solution, let me know.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(