Comments (5)
@vedantnn71 I think you need to use Controller for that.
...
import { Controller, useForm } from 'react-hook-form';
export default function Survey() {
const {
register,
handleSubmit,
formState: { errors },
reset,
control,
} = useForm<{
isDesktop: boolean;
}>();
...
return (
<form>
<Label htmlFor="isDesktop">
Are you using a desktop version of our app?
</Label>
<Controller
control={control}
name="isDesktop"
render={({ field: { onChange, value, ref } }) => (
<Checkbox onCheckedChange={onChange} checked={value} ref={ref} />
)}
/>
<button>Submit</button>
</form>
);
}
from ui.
Example for select input with react hook form controller. Confusing part for me was that the HTML select element is the SelectContent
element
<Controller
control={control}
name="jobPostEmployment"
render={({
field: { onChange, onBlur, value, name, ref },
fieldState: { invalid, isTouched, isDirty, error },
formState,
}) => (
<div>
<Select name={name} onValueChange={onChange} defaultValue={value}>
<SelectTrigger className="w-[180px] mt-2">
<SelectValue placeholder={formatSelectValue(value)} />
</SelectTrigger>
<SelectContent ref={ref}>
<SelectItem
value={
AdbJobPostEmploymentType.JobPostEmploymentTypeFullTime
}
>
{formatSelectValue(
AdbJobPostEmploymentType.JobPostEmploymentTypeFullTime
)}
</SelectItem>
<SelectItem
value={AdbJobPostEmploymentType.JobPostEmploymentTypeHourly}
>
{formatSelectValue(
AdbJobPostEmploymentType.JobPostEmploymentTypeHourly
)}
</SelectItem>
<SelectItem
value={
AdbJobPostEmploymentType.JobPostEmploymentTypePartTime
}
>
{formatSelectValue(
AdbJobPostEmploymentType.JobPostEmploymentTypePartTime
)}
</SelectItem>
</SelectContent>
</Select>
from ui.
@its-monotype thank you! that helped me to solve it!
from ui.
@austincollinpena Your comment saved my life!!! 🙏🏻
from ui.
Using this approach, how can you define stuff like "required" and "minLength"?
from ui.
Related Issues (20)
- [bug]: Combobox example does not work with [email protected] HOT 1
- [feat]: Notification Badge Component
- [bug]: Inside of a drawer form is not reseting.
- [feat]: DataTable Columns (ColumnDef) doesn't support passing of any state/functions
- [bug]: Input field not forwarded when it's in another wrapper/hoc file HOT 2
- [bug]: Initially opened dialog causes hydration error HOT 1
- [bug]: The selected indicator for radio groups is not centered HOT 1
- [feat]: Country select based on `autocomplete-select`
- [feat]: tel input uses libphonenumber-js for phone number parsing and formatting
- [feat]: Add Money Symbols to input
- [feat]: add hot toast to the library HOT 2
- [feat]: Preserve type for onValueChange in Select component.
- [bug]: Doc error - the examples in the `ComboBox` section do not work - they are missing the `CommandList` element HOT 6
- [feat]: Add `overflow-auto` and `max-h-screen` styles to popover
- [bug]: block-toolbar component on blocks page stops working if you click the currently active toggle again
- [bug]: default text-sm on textarea messes up responsivity
- [bug]: Menubar keeps closing when render by looping the data
- [feat]: Input with tags HOT 1
- [feat]: Open Drawer on swipe up
- [feat]: Carousel autoplay restart HOT 1
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 ui.