diff --git a/rollup.config.mjs b/rollup.config.mjs index 563e5af..9bb3c6f 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -26,7 +26,7 @@ const plugins = [ terser({ output: { comments: false }, compress: { - drop_console: true, + drop_console: false, }, }), ]; diff --git a/src/lib/AsyncTypeaheadInput.tsx b/src/lib/AsyncTypeaheadInput.tsx index 26a1b84..8128288 100644 --- a/src/lib/AsyncTypeaheadInput.tsx +++ b/src/lib/AsyncTypeaheadInput.tsx @@ -83,6 +83,7 @@ const AsyncTypeaheadInput = (props: AsyncTypeaheadInputPr const { name, id } = useSafeNameId(props.name ?? "", props.id); const { setDebounceSearch, isLoading } = useDebounceHook(queryFn, setOptions); const { control, disabled: formDisabled, getFieldState, setValue: setFormValue } = useFormContext(); + const isDisabled = useMemo(() => formDisabled || disabled, [formDisabled, disabled]); validateFixedOptions(fixedOptions, multiple, autocompleteProps, withFixedOptionsInValue, value); @@ -91,6 +92,7 @@ const AsyncTypeaheadInput = (props: AsyncTypeaheadInputPr } = useController({ name, control, + shouldUnregister: isDisabled, rules: { validate: { required: () => getFieldState(name)?.error?.message, @@ -98,7 +100,6 @@ const AsyncTypeaheadInput = (props: AsyncTypeaheadInputPr }, }); - const isDisabled = useMemo(() => formDisabled || disabled, [formDisabled, disabled]); const paginatedOptions = useMemo( () => (limitResults === undefined ? options : options.slice(0, page * limitResults)), [limitResults, page, options], diff --git a/src/lib/DatePickerInput.tsx b/src/lib/DatePickerInput.tsx index c25d664..045fecb 100644 --- a/src/lib/DatePickerInput.tsx +++ b/src/lib/DatePickerInput.tsx @@ -129,6 +129,7 @@ const DatePickerInput = (props: DatePickerInputProps) return ( ( diff --git a/src/lib/FormattedInput.tsx b/src/lib/FormattedInput.tsx index c931b3b..fdeb238 100644 --- a/src/lib/FormattedInput.tsx +++ b/src/lib/FormattedInput.tsx @@ -46,6 +46,7 @@ const FormattedInput = (props: FormattedInputProps) => { const commonProps: NumericFormatProps = { name: name, diff --git a/src/lib/RatingInput.tsx b/src/lib/RatingInput.tsx index d245758..88c858b 100644 --- a/src/lib/RatingInput.tsx +++ b/src/lib/RatingInput.tsx @@ -29,6 +29,7 @@ const RatingInput = (props: RatingInputProps) => { return ( ( (props: StaticTypeaheadInput const { name, id } = useSafeNameId(props.name ?? "", props.id); const { control, disabled: formDisabled, getFieldState, clearErrors, watch } = useFormContext(); + const isDisabled = useMemo(() => formDisabled || disabled, [formDisabled, disabled]); + const { field: { ref, ...field }, } = useController({ name, control, + shouldUnregister: isDisabled, rules: { validate: { required: () => getFieldState(name)?.error?.message, @@ -84,7 +87,6 @@ const StaticTypeaheadInput = (props: StaticTypeaheadInput }, }); - const isDisabled = useMemo(() => formDisabled || disabled, [formDisabled, disabled]); const paginatedOptions = useMemo( () => (limitResults === undefined ? options : options.slice(0, page * limitResults)), [limitResults, page, options], diff --git a/src/lib/components/ColorPicker/ColorPicker.tsx b/src/lib/components/ColorPicker/ColorPicker.tsx index 65b7168..ee17ade 100644 --- a/src/lib/components/ColorPicker/ColorPicker.tsx +++ b/src/lib/components/ColorPicker/ColorPicker.tsx @@ -56,6 +56,7 @@ const ColorPicker = (props: ColorPickerInputProps) => } = useController({ name, control, + shouldUnregister: true, rules: { validate: { required: () => getFieldState(name)?.error?.message, diff --git a/src/lib/components/Input/InputInternal.tsx b/src/lib/components/Input/InputInternal.tsx index 892591d..98b45d0 100644 --- a/src/lib/components/Input/InputInternal.tsx +++ b/src/lib/components/Input/InputInternal.tsx @@ -43,6 +43,7 @@ const InputInternal = (props: InputProps) => { } = useFormContext(); const { ref, ...rest } = register(name, { + // disabled: formDisabled || disabled, // FIXME this one unregister on submit setValueAs: (value: string) => (value === UNDEFINED_OPTION_VALUE ? undefined : value), }); @@ -69,7 +70,7 @@ const InputInternal = (props: InputProps) => { maxLength={maxLength} rows={textAreaRows} multiple={multiple} - disabled={formDisabled || disabled} + disabled={formDisabled || disabled} // this one just disables the input plaintext={plainText} style={plainText ? { color: "black", marginLeft: 10, ...style } : { ...style }} placeholder={placeholder} @@ -88,12 +89,23 @@ const InputInternal = (props: InputProps) => { })(); }} onChange={(e) => { + console.log("event before the IIFE-->", e); + void (async () => { + // if (onChange) { + // onChange(e); + // } + + // setTimeout(async () => { + // console.log("event after the IIFE-->", e); + // }, 1000); + + await rest.onChange(e); + if (onChange) { + console.log("calling custom onChange", e); onChange(e); } - - await rest.onChange(e); })(); }} onKeyDown={onKeyDown}