Skip to content

Commit

Permalink
fix: display error for untouched hidden field (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
totraev authored Jan 6, 2025
1 parent cf53263 commit 99f593f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-tools-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@babylonlabs-io/bbn-core-ui": patch
---

fix hidden field
23 changes: 13 additions & 10 deletions src/widgets/form/HiddenField/HiddenField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ export interface HiddenFieldProps extends FieldProps {
}

export function HiddenField({ displayError = false, ...props }: HiddenFieldProps) {
const { invalid, error, value, onChange, onBlur, disabled, name, ref } = useField(props);
const { error, value, onChange, onBlur, disabled, name, ref } = useField(props);

const fieldState = invalid && displayError ? "error" : "default";
const fieldHint = invalid && displayError ? error : "";
const input = (
<input ref={ref} type="hidden" name={name} disabled={disabled} value={value} onChange={onChange} onBlur={onBlur} />
);

return displayError ? (
<FormControl hint={fieldHint} state={fieldState}>
{input}
</FormControl>
) : (
input
);
if (displayError) {
const fieldState = displayError ? "error" : "default";
const fieldHint = displayError ? error : "";

return (
<FormControl hint={fieldHint} state={fieldState}>
{input}
</FormControl>
);
}

return input;
}

0 comments on commit 99f593f

Please sign in to comment.