Skip to content

The console shows variable not found but it is working properly (inside the custom directive) #4409

Answered by ekwoka
RussBaz asked this question in 1. Help
Discussion options

You must be logged in to vote

Why are you doing that in the directive?

Anyway, the root cause is that the original elements are being queued to initialize, but you remove them from the dom, and they then initialize while detached.

Specifically solving it in your example would be

Alpine.directive("form", (el) => {
  const fieldset = document.createElement('fieldset');
  fieldset.append(...el.children);
  el.append(fieldset)
});

so that you reuse the same elements.

but why are you doing this kind of wrapping at all?

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@ekwoka
Comment options

Answer selected by RussBaz
@RussBaz
Comment options

@ekwoka
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants