Merge pull request #1327 from rowyio/fix/create-table-name-glitch

fix create table form table name glitches
This commit is contained in:
Shams
2023-07-03 18:24:51 +02:00
committed by GitHub

View File

@@ -20,10 +20,14 @@ export default function TableName({ watchedField, ...props }: ITableNameProps) {
const watchedValue = useWatch({ control, name: watchedField } as any);
useEffect(() => {
if (!disabled) {
if (typeof value === "string" && value.trim() !== "") {
onChange(value);
} else if (typeof watchedValue === "string" && !!watchedValue) {
const touched = control.getFieldState(props.name).isTouched;
if (!touched && typeof watchedValue === "string" && !!watchedValue) {
// if table name field is not touched, and watched value is valid, set table name to watched value
onChange(startCase(watchedValue));
} else if (typeof value === "string") {
// otherwise if table name is valid, set watched value to table name
onChange(value.trim());
}
}
}, [watchedValue, disabled, onChange, value]);