Comments (4)
I wrote an implementation of FieldArray
for svelte-forms-lib. I don't want to spend much more time on it since I'm probably going to switch to svelte-final-form, but I could probably push up a PR if anyone is interested.
Here's an example of how it looks to use it:
<FieldArray name="users" let:fields>
{#each fields.entries() as [name, i]}
<div class="form-group">
<div>
<Field
name={`${name}.name`}
type="text"
let:field
>
<input
{...field.input}
on:input={field['on:input']}
on:blur={field.handleChange}
placeholder={`Name of person #${i + 1}`}
/>
{#if field.error}
<small class="error">{field.error}</small>
{/if}
</Field>
</div>
<div>
<Field
name={`${name}.email`}
type="email"
let:field
>
<input
{...field.input}
on:input={field['on:input']}
on:blur={field.handleChange}
placeholder="E-mail address"
/>
{#if field.error}
<small class="error">{field.error}</small>
{/if}
</Field>
</div>
<button type="button" on:click={fields.remove(i)}>-</button>
</div>
{/each}
<div class="button-group">
<button type="button" on:click={() => fields.push({ name: "", email: "" })}>+</button>
<button type="button" on:click={handleSubmit}>submit</button>
<button type="button" on:click={handleReset}>reset</button>
</div>
</FieldArray>
from svelte-forms-lib.
@TylerRick never heard of Final Form, thanks for linking to the Svelte implementation - Final Form's approach sounds excellent!
If you've got something ready to push as a PR that'd be great :)
from svelte-forms-lib.
Well, I just discovered that there is a svelte-final-form project, so I will probably be abandoning svelte-forms-lib and switching to svelte-final-form... because final-form is awesome, and a more mature forms library, and what I had been wanting for svelte was a port of react-final-form anyway (I just didn't know one existed until today). 😄
from svelte-forms-lib.
@TylerRick I would be really interested in the PR for this if you still have the code available.
from svelte-forms-lib.
Related Issues (20)
- OnChange (handleChange func) HOT 2
- Add support for Form Arrays for Helper Components
- $errors first string, then array HOT 1
- Prototype Pollution
- Document best practices for handling form submission
- View 'global' error on validationSchema's yup object
- Uncaught (in promise) TypeError: Cannot read property '$$' of null HOT 3
- Validation with nested objects behaves inconsistently HOT 1
- Is this project maintained? HOT 1
- Export FormState type
- Adding useField() functionality HOT 1
- Where can I find the documentation for v2? HOT 1
- $errors is not returning error messages for simple arrays (yup.array(yup.string().require()) HOT 1
- set errors when using helpers HOT 1
- What is the correct way to update a property in touched store that is array of objects?
- Have form.reset() HOT 2
- Manually modify initialValues HOT 1
- Add alternatives to validationSchema HOT 1
- Vite Warning: Svelte field in package.json but no export condition for svelte. HOT 1
- onSubmit Function Behaves Inappropriate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-forms-lib.