import { useLocal } from "@/utils/use-local"; import { FC, useEffect } from "react"; import { FieldProp } from "../typings"; import { useField } from "../utils/use-field"; import { validate } from "../utils/validate"; import { FieldInput } from "./FieldInput"; import { Label } from "./Label"; export const Field: FC = (arg) => { const showlabel = arg.show_label || "y"; let type: any = typeof arg.type === "function" ? arg.type() : arg.type; // tipe field let sub_type: any = arg.sub_type; // tipe field const { fm } = arg; const field = useField(arg); const name = field.name; const local = useLocal({ prev_val: fm.data[name] }); const mode = fm.props.label_mode; const w = field.width; useEffect(() => { if (local.prev_val !== fm.data[name]) { validate(field, fm); fm.events.on_change(name, fm.data[name]); fm.render(); } }, [fm.data[name]]); if (field.status === "init" && !isEditor) return null; const errors = fm.error.get(name); const props = { ...arg.props }; delete props.className; if (type === "-" || !type || sub_type === "-" || !sub_type) { return ( <>
⚠️ Field {arg.label} is not ready
{arg.msg_error}
); } if ( (type === "multi-option" && sub_type === "-") || (type === "multi-option" && sub_type === "table-edit" && (!arg.gen_table || arg.gen_table === "")) ) { return ( <>
⚠️ Table Edit {arg.label} is not ready
{arg.msg_error}
); } return (