Git Product home page Git Product logo

Comments (2)

aadito123 avatar aadito123 commented on May 28, 2024 1

Sorry this took us a while. It seems the array fields have some issue with primitive type elements. This seems to extend to React, too.

https://stackblitz.com/edit/solid-vite-axp2zs?file=src%2Findex.tsx

Made some changes in your example to make it work. We'll likely rollout a fix to support primitive types though.

from form.

crutchcorn avatar crutchcorn commented on May 28, 2024

Thanks for reporting this!

I noticed your syntax is a bit off from what 0.14 is expecting. This should fix that:

import { render } from 'solid-js/web';
import { createForm } from '@tanstack/solid-form';
import { Index, Show } from 'solid-js';

function Counter() {
  const form = createForm(() => ({
    defaultValues: {
      names: ['1', '2', '3'] as string[],
    },
  }));

  return (
    <>
      <form>
        <form.Field
          name="names"
          mode="array"
          children={(namesField) => (
            <div>
              Names
              <div>
                <Show when={namesField().state.value.length > 0}>
                  <Index each={namesField().state.value}>
                    {(_, i) => (
                      <form.Field name={`names[${i}]` as never}>
                        {(field) => {
                          return (
                            <div>
                              <label for={field().name}>Name:</label>
                              <input
                                id={field().name}
                                name={field().name}
                                value={field().state.value}
                                onBlur={field().handleBlur}
                                onInput={(e) =>
                                  field().handleChange(e.target.value as never)
                                }
                              />
                              <button
                                type="button"
                                onClick={() => namesField().removeValue(i)}
                              >
                                X
                              </button>
                            </div>
                          );
                        }}
                      </form.Field>
                    )}
                  </Index>
                </Show>
              </div>
              <button type="button" onClick={() => namesField().pushValue('')}>
                Add name
              </button>
            </div>
          )}
        />
      </form>
    </>
  );
}

render(() => <Counter />, document.getElementById('app')!);

That said, this doesn't fix the bug. Let me investigate and add some failing tests so we can fix it.

from form.

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.