Skip to content

Qwik: form loader not loading, unexpected <Field/> type error #263

Open
@genox

Description

@genox

Hi,

I have this route:

import { component$ } from '@builder.io/qwik';
import type { DocumentHead } from '@builder.io/qwik-city';
import { routeLoader$ } from '@builder.io/qwik-city';
import { Button, Card, Heading, Input } from 'flowbite-qwik';
import { _ } from 'compiled-i18n';
import { useProfileLoader } from '~/lib/route-loader/data/use-profile-loader';
import type { InitialValues } from '@modular-forms/qwik';
import { useForm, valiForm$ } from '@modular-forms/qwik';
import * as v from 'valibot';

export { useProfileLoader };

const ProfileSchema = v.object({
  firstname: v.pipe(v.string(), v.nonEmpty('Please enter your firstname.')),
  name: v.pipe(v.string(), v.nonEmpty('Please enter your family name.')),
});

type ProfileForm = v.InferInput<typeof ProfileSchema>;

export const useFormLoader = routeLoader$<InitialValues<ProfileForm>>(async (requestEvent) => {
  const profile = await requestEvent.resolveValue(useProfileLoader);
  if (!profile) {
    return {
      firstname: 'test',
      name: 'test',
    };
  }
  console.log(profile);
  const { firstname, name } = profile;
  return {
    firstname,
    name,
  };
});

export default component$(() => {
  const [profileForm, { Form, Field }] = useForm<ProfileForm>({
    loader: useFormLoader(),
    validate: valiForm$(ProfileSchema),
  });

  return (
    <Card>
      <div class={'flex flex-col gap-8'}>
        <Heading tag={'h2'}>{_`Your Profile`}</Heading>
        <Form>
          <Field name="firstname">{(field, props) => <Input {...props} type="email" />}</Field>
          <Field name="name">{(field, props) => <Input {...props} type="text" />}</Field>
          <Button type="submit">{_`Save`}</Button>
        </Form>
      </div>
    </Card>
  );
});

Issues

  1. The form is not being populated with initial values, even though the routeLoader correctly logs the data on the server side
  2. complains about a missing of= attribute that should be the formStore (profileForm), but even when supplying that it complains about mismatched types. Has no effect on missing initial values.

I mainly followed the tutorial on your website since I was away for a while and just returned to working with Qwik and didn't want to run into breaking changes I was not aware of.

I can't find anything that makes this differ much from the example, yet it doesn't work and there are weird type issues that should not (no?) be there. can you see something obvious?

Thanks for having a look

Versions:

node 22, ts 5.6.2

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions