Code Monkey home page Code Monkey logo

Comments (4)

TylerRick avatar TylerRick commented on May 27, 2024 1

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.

larrybotha avatar larrybotha commented on May 27, 2024 1

@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.

TylerRick avatar TylerRick commented on May 27, 2024

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.

silentworks avatar silentworks commented on May 27, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.