Comments (7)
Yup, the register
approach is for uncontrolled components only. If you'd like to make it work with controlled components, you'll need to use Controller
or implement value
and onChange
by hand, using setValue
to set the value.
But I think the API you suggested is good for uncontrolled custom inputs. I'll leave the issue open until we implement it.
from remix-forms.
Note - For those who see the above and a wondering whats going on. When using Controller, if the render
of the controller doesn't put a hidden or otherwise input into the dom, this won't work. So its a matter of adding
<Controller
name="dateStart"
control={control}
render={({ field }) => (
<>
<input name={field.name} value={field.value} type="hidden" />
<Calendar
id={field.name}
value={field.value}
onChange={(e) => field.onChange(e.value)}
/>
<>
)}
/>
Hope this helps
from remix-forms.
Swweeeet, I think we can move with this API. The controller component doesn't care we have registered it before. I'll take a dive into the code later to see if I can manage to make that
from remix-forms.
Hey, @wladiston! That's a great idea and I agree with your suggested API :D thanks!
Would you like to send a PR with this?
from remix-forms.
Probably not... I'm doing some tests with that build-in registration and I'm running into some trouble.
I have this scenario where I'm usiing a 3rd party phone number input that masks the user input with the correct country format. This component only exposes controllable props. It only works well with the defaultValues and etc, if I let the component Controller from react-hook-form handles the registration and render for me.
import { useForm, Controller } from "react-hook-form";
import PhoneInput, { isValidPhoneNumber } from "react-phone-number-input";
....
<Controller
name="phone-input"
control={control}
rules={{
validate: (value) => isValidPhoneNumber(value)
}}
render={({ field: { onChange, value } }) => (
<PhoneInput
value={value}
onChange={onChange}
defaultCountry="TH"
id="phone-input"
/>
)}
/>
Forgot to mention that if I make the registration by myself this. component breaks miserably. On those kinda of components we don't want preregister anythiing
PS: they are actually mention that in their doc
https://react-hook-form.com/api/usecontroller/controller/
React Hook Form embraces uncontrolled components and native inputs, however it's hard to avoid working with external controlled component such as React-Select, AntD and Material-UI. This wrapper component will make it easier for you to work with them.
from remix-forms.
I'm still struggling with this. I'm using primereact controlled component and the dateStart
value is always null. Am I missing something?
...
{({ Field, Button, Errors, control }) => (
<>
<Field name="dateStart">
{({ Label, Errors }) => (
<>
<Label />
<Controller
name="dateStart"
control={control}
render={({ field }) => (
<Calendar
id={field.name}
value={field.value}
onChange={(e) => field.onChange(e.value)}
/>
)}
/>
<Errors />
</>
)}
</Field>
...
I'm following primereact's example: https://www.primefaces.org/primereact/reacthookform/
from remix-forms.
I'm closing this issue because - at least for now - we don't want to increase our API with helpers for custom components when react-hook-form already has a great API for that.
from remix-forms.
Related Issues (20)
- Attach errors to Fields that are dynamically generated? HOT 2
- Inconsistent display of selected option in select control HOT 4
- Custom Component typings HOT 2
- Error: Cannot submit element that is not <form>, <button>, or <input type="submit|image"> HOT 1
- Multiple Checkboxes HOT 3
- Define Input type through fieldTypes HOT 5
- Bring `errorMessagesForSchema` from `domain-functions` to this library HOT 1
- form with mode="onChange" button flashes when it hydrates HOT 2
- Could not resolve "@deepkit/type" HOT 3
- Overriding fields HOT 2
- <Field hidden /> is not passing `type="hidden"` to its input
- Validation error not shown when field is an array
- Can't trigger onSubmit from Form-component HOT 6
- Handle `z.object` HOT 1
- Can remix-forms function within a PWA / client side only context? HOT 4
- Zod schema array of objects HOT 1
- Remix forms site example no longer maintained? HOT 1
- [BUG] Field error(s) not showing if using additional component HOT 1
- Input ID's not always unique when multiple forms are rendered
- Example of how to do crud correctly?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remix-forms.