|
18 | 18 | import { slugify } from "@/utils"; |
19 | 19 | import { Badge } from "@/components/ui/badge"; |
20 | 20 | import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; |
21 | | - import { FieldMeta } from "@/form/types"; |
| 21 | + import { FieldMeta, FormFieldEmitInputOptions } from "@/form/types"; |
22 | 22 | import StickyTop from "@/components/StickyTop.vue"; |
23 | 23 | import StickyBottom from "@/components/StickyBottom.vue"; |
24 | 24 | import { Menu } from 'lucide-vue-next'; |
25 | 25 | import { Label } from "@/components/ui/label"; |
26 | 26 | import RootCardHeader from "@/components/ui/RootCardHeader.vue"; |
27 | 27 | import { vScrollIntoView } from "@/directives/scroll-into-view"; |
28 | 28 | import { useResizeObserver } from "@vueuse/core"; |
| 29 | + import debounce from "lodash/debounce"; |
| 30 | + import { api } from "@/api/api"; |
| 31 | + import { route } from "@/utils/url"; |
| 32 | + import { useParentCommands } from "@/commands/useCommands"; |
| 33 | + import merge from 'lodash/merge'; |
29 | 34 |
|
30 | 35 | const props = defineProps<{ |
31 | 36 | form: Form |
|
77 | 82 | props.form.setMeta(fieldKey, { uploading }); |
78 | 83 | } |
79 | 84 |
|
80 | | - function onFieldInput(fieldKey: string, value: FormFieldData['value'], { force = false } = {}) { |
| 85 | + const parentCommands = useParentCommands(); |
| 86 | + const refresh = debounce((data) => { |
| 87 | + api.post(route('code16.sharp.api.form.refresh.update', { |
| 88 | + entityKey: props.form.entityKey, |
| 89 | + instance_id: props.form.instanceId, |
| 90 | + embed_key: props.form.embedKey, |
| 91 | + entity_list_command_key: parentCommands?.commandContainer === 'entityList' ? props.form.commandKey : null, |
| 92 | + show_command_key: parentCommands?.commandContainer === 'show' ? props.form.commandKey : null, |
| 93 | + }), data) |
| 94 | + .then(response => { |
| 95 | + props.form.data = merge({}, props.form.data, response.data.form.data); |
| 96 | + }); |
| 97 | + }, 200); |
| 98 | +
|
| 99 | + function onFieldInput(fieldKey: string, value: FormFieldData['value'], inputOptions: FormFieldEmitInputOptions = {}) { |
81 | 100 | const data = { |
82 | 101 | ...props.form.data, |
83 | | - ...(!force ? getDependantFieldsResetData(props.form.fields, fieldKey) : null), |
| 102 | + ...(!inputOptions.force ? getDependantFieldsResetData(props.form.fields, fieldKey) : null), |
84 | 103 | [fieldKey]: value, |
85 | 104 | }; |
86 | 105 |
|
| 106 | + if((props.form.shouldRefresh(fieldKey) || inputOptions.shouldRefresh) && !inputOptions.skipRefresh) { |
| 107 | + refresh(data); |
| 108 | + } |
| 109 | +
|
87 | 110 | props.form.data = data; |
88 | 111 | props.form.serializedData = data; |
89 | 112 | } |
|
0 commit comments