Skip to content

setResponse and throwing FormError doesn't work anymore #161

Open
@Przemoo16

Description

Again, thank you so much for a great job by creating this library!!!

After upgrading Qwik to the latest 1.3.0 version, using setResponse or throwing FormError doesn't display the response message if the validation is defined. After removing the validate property it works as expected.

Could be related to this issue: #158

Code to reproduce (Remove the validate={[required('Field is required.')]} to make it works):

import { $, component$ } from '@builder.io/qwik';
import {
  FormError,
  required,
  setResponse,
  type SubmitHandler,
  useForm,
} from '@modular-forms/qwik';

export type TestForm = {
  myInput: string;
};

export default component$(() => {
  const [form, { Form, Field }] = useForm<TestForm>({
    loader: { value: { myInput: '' } },
  });

  const handleSubmit = $<SubmitHandler<TestForm>>(async (_values, _event) => {
    throw new FormError<TestForm>('ERROR');
    // setResponse(form, { message: 'RESPONSE' });
  });

  return (
    <Form onSubmit$={handleSubmit}>
      <Field name="myInput" validate={[required('Field is required.')]}>
        {(field, props) => <input {...props} type="text" />}
      </Field>
      <div>{form.response.message}</div>
      <button type="submit">Submit</button>
    </Form>
  );
});

Dependencies:

    "@builder.io/qwik": "^1.3.0",
    "@builder.io/qwik-city": "^1.3.0",
    "@modular-forms/qwik": "^0.21.2",
    "@types/node": "^20.10.1",
    "typescript": "^5.3.2",
    "undici": "^5.28.2",
    "vite": "^5.0.7",
    "vite-tsconfig-paths": "^4.2.1",
    "vitest": "^1.0.1"

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions