Loading...
Loading...
₹3,000
/ day"use client"; import * as React from "react"; import { Controller, FieldValues, Path, RegisterOptions, useFormContext, } from "react-hook-form"; import Select from "../../input/BaseSelect"; import { FormField } from "./FormField"; import { BaseFormFieldProps } from "../types/form-input.types"; import { getNestedError } from "../utils/form.utils"; export interface SelectOption { label: React.ReactNode; value: string | number; disabled?: boolean; } interface FormSelectProps<T extends FieldValues> extends BaseFormFieldProps, Omit React.ComponentProps<typeof Select>, "name" | "className" | "children" | "value" | "onChange" > { name: Path<T>; rules?: RegisterOptions<T, Path<T>>; placeholder?: string; options: SelectOption[] | ((values: T) => SelectOption[]); } export function FormSelect<T extends FieldValues>({ name, label, helperText, rules, hideLabel = false, hideError = false, classNames, id, required, placeholder, options, ...props }: FormSelectProps<T>) { const { control, watch, formState: { errors }, } = useFormContext<T>(); const values = watch(); const finalOptions = React.useMemo(() => { return typeof options === "function" ? options(values) : options; }, [options, values]); const error = getNestedError(errors, name)?.message as string | undefined; const inputId = id ?? name; return ( <FormField id={inputId} label={label} required={required} error={error} helperText={helperText} hideLabel={hideLabel} hideError={hideError} classNames={classNames} > <Controller name={name} control={control} rules={rules} render={({ field }) => { // If the currently held value is no longer a valid // option (e.g. brand changed under a dependent model // select), fall back to "" so DOM and RHF always agree. const isValid = finalOptions.some( (opt) => opt.value === field.value ); const safeValue = isValid ? field.value ?? "" : ""; return ( <Select id={inputId} aria-invalid={!!error} className={classNames?.input} {...props} name={field.name} ref={field.ref} value={safeValue} onChange={(e) => field.onChange(e.target.value)} onBlur={field.onBlur} > {placeholder && ( <option value="" disabled hidden> {placeholder} </option> )} {finalOptions.map((option) => ( <option key={option.value} value={option.value} disabled={option.disabled} > {option.label} </option> ))} </Select> ); }} /> </FormField> ); }
Car Number
HP89HC0216
Transmission
automatic
No. Of Doors
3
Color
white
Fuel Type
hybrid
Category
Economy
No. Of Seats
2
Car Type
minivan
Brand
Mahindra
Model
Thar
Year
2026





Pickup Address
Entire rental unit in Shimla, India, shimla, Himachal Pradesh, india