mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-06-21 11:51:53 +03:00
add prop to disable id field
This commit is contained in:
parent
7e0e0635b8
commit
709a54ade4
@ -26,6 +26,7 @@ type NameAndIdFieldsProps<T extends FieldValues = FieldValues> = {
|
|||||||
placeholderName?: string;
|
placeholderName?: string;
|
||||||
placeholderId?: string;
|
placeholderId?: string;
|
||||||
idVisible?: boolean;
|
idVisible?: boolean;
|
||||||
|
idDisabled?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function NameAndIdFields<T extends FieldValues = FieldValues>({
|
export default function NameAndIdFields<T extends FieldValues = FieldValues>({
|
||||||
@ -41,6 +42,7 @@ export default function NameAndIdFields<T extends FieldValues = FieldValues>({
|
|||||||
placeholderName,
|
placeholderName,
|
||||||
placeholderId,
|
placeholderId,
|
||||||
idVisible,
|
idVisible,
|
||||||
|
idDisabled,
|
||||||
}: NameAndIdFieldsProps<T>) {
|
}: NameAndIdFieldsProps<T>) {
|
||||||
const { t } = useTranslation(["common"]);
|
const { t } = useTranslation(["common"]);
|
||||||
const { watch, setValue, trigger, formState } = useFormContext<T>();
|
const { watch, setValue, trigger, formState } = useFormContext<T>();
|
||||||
@ -59,6 +61,9 @@ export default function NameAndIdFields<T extends FieldValues = FieldValues>({
|
|||||||
const effectiveProcessId = processId || defaultProcessId;
|
const effectiveProcessId = processId || defaultProcessId;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (idDisabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const subscription = watch((value, { name }) => {
|
const subscription = watch((value, { name }) => {
|
||||||
if (name === nameField) {
|
if (name === nameField) {
|
||||||
hasUserTypedRef.current = true;
|
hasUserTypedRef.current = true;
|
||||||
@ -68,7 +73,15 @@ export default function NameAndIdFields<T extends FieldValues = FieldValues>({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return () => subscription.unsubscribe();
|
return () => subscription.unsubscribe();
|
||||||
}, [watch, setValue, trigger, nameField, idField, effectiveProcessId]);
|
}, [
|
||||||
|
watch,
|
||||||
|
setValue,
|
||||||
|
trigger,
|
||||||
|
nameField,
|
||||||
|
idField,
|
||||||
|
effectiveProcessId,
|
||||||
|
idDisabled,
|
||||||
|
]);
|
||||||
|
|
||||||
// Auto-expand if there's an error on the ID field after user has typed
|
// Auto-expand if there's an error on the ID field after user has typed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -123,6 +136,7 @@ export default function NameAndIdFields<T extends FieldValues = FieldValues>({
|
|||||||
<Input
|
<Input
|
||||||
className="text-md"
|
className="text-md"
|
||||||
placeholder={placeholderId}
|
placeholder={placeholderId}
|
||||||
|
disabled={idDisabled}
|
||||||
{...field}
|
{...field}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user