Skip to content

Radio buttons not working with numeric value #273

Open
@PeterDraex

Description

I've read the docs and implemented a form with radio buttons, but when you click on a radio button, the form state is not updated.

Here is a simplified code example.

const entities = [
  { id: 1, label: 'one' },
  { id: 2, label: 'two' },
];

type RadioForm = {
  entityID: number;
};
<For each={entities}>
  {(entity) => (
    <Field name="entityID" type="number">
      {(field, props) => (
        <label>
          <input
            {...props}
            type="radio"
            value={entity.id}
            checked={field.value == entity.id}
          />
          {entity.label}
        </label>
      )}
    </Field>
  )}
</For>
Current value: {getValue(radioForm, 'entityID')}

Manually adding onChange={(e) => setValue(radioForm, 'entityID', parseInt(e.target.value))} to the input fixes the issue, but I'm guessing that's not the correct use, since no other input type requires manually setting the new value.

The full example is available on Stackblitz.

Is this a bug?

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions