Giter Club home page Giter Club logo

Comments (5)

its-monotype avatar its-monotype commented on May 21, 2024 2

@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.

austincollinpena avatar austincollinpena commented on May 21, 2024 2

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.

valerius21 avatar valerius21 commented on May 21, 2024

@its-monotype thank you! that helped me to solve it!

from ui.

Angelfire avatar Angelfire commented on May 21, 2024

@austincollinpena Your comment saved my life!!! 🙏🏻

from ui.

MaximilianLloyd avatar MaximilianLloyd commented on May 21, 2024

Using this approach, how can you define stuff like "required" and "minLength"?

from ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.