kajetansw / solar-forms Goto Github PK
View Code? Open in Web Editor NEWForms library for SolidJS inspired by Angular's reactive forms.
License: MIT License
Forms library for SolidJS inspired by Angular's reactive forms.
License: MIT License
Hey, so pretty simple issue if you have a form
like this
<Show when={true}>
<form use:formGroup={fg}>
<input type="text" formControlName="email" />
</form>
</Show>
Essentially, the input field gets deselected every time you input a character.
Here is a repo with an example.
A quick discussion on the Solid-js Discord found that the issue is with solid-js@>1.4.7
in the playground, the Repo uses [email protected]
Breaks
Works
Maybe you can shed some light on it ?
Thanks for creating this library. While testing I have come across a couple of related issues.
e.g. An input
in a div
will not be seen by the formGroup
function.
<form use:formGroup={fg}>
<div>
<input type="email" formControlName="email" />
<div>
</form>
This was solved by adding a couple of lines to the bottom of the formGroup
function to recurse through elements...
export function formGroup<I extends CreateFormGroupInput>(el: Element, formGroupSignal: () => FormGroup<I>) {
for (const $child of el.children) {
const formGroupName = getFormGroupName($child);
if (formGroupName) {
// Handle nested form groups
formGroup($child, toNestedFormGroupSignal(formGroupSignal, formGroupName));
} else {
const $formControl = getFormControl($child);
if ($formControl instanceof HTMLInputElement) {
formGroupForInput($formControl, formGroupSignal);
} else if ($formControl instanceof HTMLSelectElement) {
formGroupForSelect($formControl, formGroupSignal);
} else if ($formControl instanceof HTMLTextAreaElement) {
formGroupForTextArea($formControl, formGroupSignal);
} else if ($formControl == null && $child instanceof Element && $child.children.length > 0) {
// Handle nested elements
formGroup($child, formGroupSignal);
}
}
}
}
e.g.
<form use:formGroup={fg}>
<MyFields />
</form>
function MyFields() {
return (
<input type="email" formControlName="email" />
)
}
Even with the above patch this does not work because formGroup
is being used as a directive. It gets executed when the form element is created but before the MyFields
elements exist (or at least that's my understanding). I was able to work around this by not using formGroup
as a directive but instead calling it from onMount
with a ref
to the form
.
let formRef;
onMount(() => {
formGroup(formRef, () => fg)
})
return (
<form ref={formRef}>
<MyFields />
</form>
)
Maybe worth mentioning in the docs if there isn't a better solution?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.