Run script even if component is not mounted #14648
-
Describe the problemRe-submission of kit#13123 to here. I want to run some code in a component in Describe the proposed solutionSet using Alternatives consideredAlso set using Another alternative is a different block, {#run} or {#always}, that implements either the proposed or the alternative solution, but instead of changing component options, a new template block is introduced. Additional InformationFor example when there is Importancewould make my life easier |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
This is a very weird request. Can you describe at least one use-case (which I assume you have already)? |
Beta Was this translation helpful? Give feedback.
-
The use case I have in mind is that I have many forms with questions conditionally rendered with |
Beta Was this translation helpful? Give feedback.
-
I see. I would suggest creating a Form component that uses a |
Beta Was this translation helpful? Give feedback.
-
Hmm, a simpler way that doesn't use |
Beta Was this translation helpful? Give feedback.
-
Thanks for the replies. I have to play around with |
Beta Was this translation helpful? Give feedback.
-
Hello, again. This is where things get fuzzy. If you want the complete form schema, regardless of which components actually mount, there are 2 possible scenarios:
If it is the first one, just program your fields at development time. If it is the second one, how does it differ from collecting the fields as they appear? But let's say there's a difference somehow: Just have the root component (the component that has all the IF blocks) register all possible fields. If this still doesn't apply to your use case, I guess I'll have to know about your use case. |
Beta Was this translation helpful? Give feedback.
-
We're not going to add logic to run a component's script without actually mounting it. I'm converting this to a discussion since there are potentially a few workaround available. Another potential one would be to not use |
Beta Was this translation helpful? Give feedback.
-
You should not use the DOM to build your validation schema. Thats the wrong way around. Create a validation schema with code (zod, valibot, typebox, jsonschema, ...) and use that to create the DOM. I dont know of any validation library that does it the other way around |
Beta Was this translation helpful? Give feedback.
-
Before this issue/discussion I have a prototype version with |
Beta Was this translation helpful? Give feedback.
We're not going to add logic to run a component's script without actually mounting it. I'm converting this to a discussion since there are potentially a few workaround available.
Another potential one would be to not use
#if
but instead render the whole form and hide the ones you don't want withdisplay:none