mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 23:53:05 +00:00
Improve FormInput readability
This commit is contained in:
parent
1e186e5296
commit
fd4266dde6
1 changed files with 8 additions and 5 deletions
|
|
@ -28,13 +28,16 @@ export const FormInput = <
|
|||
onChange,
|
||||
...props
|
||||
}: FormInpuProps<TFieldValues, TFieldName>) => {
|
||||
const { register } = useFormContext<TFieldValues>()
|
||||
const { onChange: onValueChange, ...registerResult } = register(name, options)
|
||||
const { onChange: onValueChange, ...registerResult } = useFormContext<TFieldValues>().register(
|
||||
name,
|
||||
options,
|
||||
)
|
||||
|
||||
const handleChange: ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||
const targetValue = e.target.value
|
||||
const formattedValue = format?.(targetValue) ?? targetValue
|
||||
e.target.value = formattedValue
|
||||
if (format) {
|
||||
e.target.value = format(e.target.value)
|
||||
}
|
||||
|
||||
onValueChange(e)
|
||||
onChange?.(e)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue