How to use this with Mantine? #121
-
I am trying to use this library with Mantine and do I have to create a custom component for every form element I use like input, textarea, select etc? to access the input props for each component? There is no direct example to use Mantine or external UI Library along with Remix Validated Forms. Please help. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 20 replies
-
Good callout about this not really being documented. That's something that could definitely be worth adding. In most cases, I think you do most likely want to create a custom component for each Mantine form component you want to use in your forms. Other libraries like react-hook-form provide ways to wire up your forms entirely at the top level without custom components, but I find that approach cumbersome at scale when you have 100+ forms in an app. So this library prioritizes conciseness at the form level at the expense of some extra wiring for each input type. Now, if you only use one date picker in your app (for example) and really don't want to create a custom component, it's definitely possible to skip that by doing something like this. const { error: myDateError, getInputProps: getDateInputProps } = useField("myDate", { formId: 'my-form' });
return (
<ValidatedForm validator={validator} id="my-form">
<MantineDatePicker {...getDateInputProps({ error: myDateError })} />
<MySubmitButton />
</ValidatedForm>
) Also, depending on your requirements, the form still works even without wiring it up with The example below will still:
But it won't:
return (
<ValidatedForm validator={validator}>
<MantineDatePicker name="myDate" />
<MySubmitButton />
</ValidatedForm>
) |
Beta Was this translation helpful? Give feedback.
-
I agree when you say it is easier and have more control when we do this way. I see that creating a wrapper around the provided Mantine component is not difficult but unwanted. Although it serves the purpose, we are able to get everything wired up properly, it would be better if there is some other workaround that is similar to this remix-forms where we get the useField for the entire form control, so we can define it as we want. Advantages I see when we have that kind of structure
I am a beginner when it comes to Remix and how to get these working but if there is a way to get this forms validated without having to write a wrapper, I would be excited. Please let me know. |
Beta Was this translation helpful? Give feedback.
-
I'm also using it with Mantine and I came up with the idea of using import { useFormContext, ValidatedForm } from "remix-validated-form";
const formContext = useFormContext("addComment");
return (
<ValidatedForm
validator={validator}
method="post"
id="addComment"
defaultValues={{
name: session?.name
}}
>
<TextInput
error={formContext.fieldErrors.name}
defaultValue={formContext.defaultValues?.name}
label="Name"
name="name"
/>
</ValidatedForm>
) |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have worked mainly with Vue and I was really surprised that some things in React doesn’t yet exist or are pretty new. Same goes for nested layouts and React Router is similar to Vue Router, which I find really good.
The thing with using `Box` is that without Tailwind it’s cumbersome to style naked divs. But with it sure, I would also prefer native div with some classes attached to it.
I‘m working on a blog for my wife with meilisearch and comment system. My backend is Strapi CMS with Postgres and for client I use Remix. All pf this I host on my VPN using Caprover, which is self-hosted PaaS lile heroku and make setup really simple.
Mateusz
|
Beta Was this translation helpful? Give feedback.
-
@airjp73 I am working on implementing Remix Validated Forms with the Shadcn UI library and Zod Validation Library, particularly focusing on integrating the Shadcn Datepicker component but couldn't find any example. Any guidance or assistance in this process would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
I agree when you say it is easier and have more control when we do this way.
I see that creating a wrapper around the provided Mantine component is not difficult but unwanted. Although it serves the purpose, we are able to get everything wired up properly, it would be better if there is some other workaround that is similar to this remix-forms where we get the useField for the entire form control, so we can define it as we want.
Advantages I see when we have that kind of structure