From 0d540214ea83f5444e7478d4f7539690810d2eba Mon Sep 17 00:00:00 2001 From: rizky Date: Wed, 28 Aug 2024 17:24:36 -0700 Subject: [PATCH] type search --- .../Datepicker/components/Datepicker.tsx | 2 - comps/form/field/Field.tsx | 4 +- comps/form/field/FieldInput.tsx | 5 ++- comps/form/field/table-edit/TableEdit.tsx | 8 +++- comps/form/field/type/TypeInput.tsx | 44 +++++++++++++++++++ comps/form/field/type/TypeUploadSingle.tsx | 5 ++- 6 files changed, 58 insertions(+), 10 deletions(-) diff --git a/comps/custom/Datepicker/components/Datepicker.tsx b/comps/custom/Datepicker/components/Datepicker.tsx index f3c1df4..2c74b78 100755 --- a/comps/custom/Datepicker/components/Datepicker.tsx +++ b/comps/custom/Datepicker/components/Datepicker.tsx @@ -96,7 +96,6 @@ const Datepicker: React.FC = ({ if (newDate.isSame(reformatDate) || newDate.isAfter(reformatDate)) { setSecondDate(nextMonth(date)); } - console.log(date) setFirstDate(date); }, [secondDate] @@ -150,7 +149,6 @@ const Datepicker: React.FC = ({ const changeSecondMonth = useCallback( (month: number) => { - console.log("ALOO") secondGotoDate( dayjs(`${secondDate.year()}-${month < 10 ? "0" : ""}${month}-01`) ); diff --git a/comps/form/field/Field.tsx b/comps/form/field/Field.tsx index b503611..75ba261 100755 --- a/comps/form/field/Field.tsx +++ b/comps/form/field/Field.tsx @@ -15,7 +15,7 @@ const prepForSum = (obj: any): any => { const new_obj: any = {}; if (obj) { for (const [k, v] of Object.entries(obj) as any) { - if (typeof v === "object" && v.id) { + if (typeof v === "object" && v?.id) { new_obj[k] = v.id; continue; } @@ -86,7 +86,7 @@ export const Field: FC = (arg) => { } if (arg.on_change) { - arg.on_change({ value: fm.data[name], name, fm }); + arg.on_change({ value: fm.data?.[name], name, fm }); } if (fm.deps.md) { diff --git a/comps/form/field/FieldInput.tsx b/comps/form/field/FieldInput.tsx index 481bdec..ef348b7 100755 --- a/comps/form/field/FieldInput.tsx +++ b/comps/form/field/FieldInput.tsx @@ -135,7 +135,7 @@ export const FieldInput: FC<{ {prefix && prefix !== "" ? (
{}, @@ -110,7 +114,7 @@ export const TableEdit: FC<{ > {child} - ); + ); }, }); } else { diff --git a/comps/form/field/type/TypeInput.tsx b/comps/form/field/type/TypeInput.tsx index 7a60bb0..7061aca 100755 --- a/comps/form/field/type/TypeInput.tsx +++ b/comps/form/field/type/TypeInput.tsx @@ -52,6 +52,10 @@ export const FieldTypeInput: FC<{ show_pass: false, change_timeout: null as any, }); + const internal = useLocal({ + render_timeout: null as any, + search_timeout: null as any, + }); let type_field = prop.sub_type; switch (type_field) { case "datetime": @@ -334,6 +338,46 @@ export const FieldTypeInput: FC<{ /> ); } + case "search": { + return ( +
+
+ + + + +
+ { + fm.data[field.name] = ev.currentTarget.value; + renderOnChange(); + if (prop.onChange) { + await prop.onChange(fm.data[field.name]); + } + + clearTimeout(internal.search_timeout); + internal.search_timeout = setTimeout(() => { + fm?.submit(); + }, 1500); + }} + /> +
+ ); + } } return (
diff --git a/comps/form/field/type/TypeUploadSingle.tsx b/comps/form/field/type/TypeUploadSingle.tsx index d0d825b..558878c 100755 --- a/comps/form/field/type/TypeUploadSingle.tsx +++ b/comps/form/field/type/TypeUploadSingle.tsx @@ -37,7 +37,7 @@ export const FieldUploadSingle: FC<{ try { file = event.target?.files?.[0]; } catch (ex) {} - if (prop.model_upload === "import") { + if (prop.sub_type === "import") { const reader = new FileReader(); function arrayBufferToBinaryString(buffer: ArrayBuffer): string { @@ -149,7 +149,8 @@ export const FieldUploadSingle: FC<{ ref={(ref) => (input.ref = ref)} type="file" multiple={false} - accept={field.prop.upload?.accept} + // accept={field.prop.upload?.accept} + accept={"file/**"} onChange={on_upload} className={cx( "c-absolute c-w-full c-h-full c-cursor-pointer c-top-0 c-left-0 c-opacity-0"