Skip to content

Commit 238163d

Browse files
set/read dataRange and timeRange data using form
1 parent 5f4861c commit 238163d

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ export const dateRangeControl = (function () {
286286
const childrenMap = {
287287
start: stringExposingStateControl("start"),
288288
end: stringExposingStateControl("end"),
289+
...formDataChildren,
289290
...commonChildren,
290291
};
291292

@@ -367,6 +368,8 @@ export const dateRangeControl = (function () {
367368
tooltip: trans("date.formatTip"),
368369
})}
369370
</Section>
371+
372+
<FormDataPropertyView {...children} />
370373

371374
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
372375
<><Section name={sectionNames.validation}>
@@ -572,4 +575,21 @@ DateRangeComp = withMethodExposing(DateRangeComp, [
572575
comp.children.end.getView().reset();
573576
},
574577
},
578+
{
579+
method: {
580+
name: "setRange",
581+
params: [],
582+
},
583+
execute: (comp, values) => {
584+
if (values.length !== 1) {
585+
return Promise.reject(trans("formComp.valuesLengthError"));
586+
}
587+
const data = values[0] as { start: string, end: string };
588+
if (typeof data !== "object" || data === null || Array.isArray(data) || !data.hasOwnProperty('start') || !data.hasOwnProperty('end')) {
589+
return Promise.reject(trans("formComp.valueTypeError"));
590+
}
591+
comp.children.start.getView().onChange(data.start);
592+
comp.children.end.getView().onChange(data.end);
593+
},
594+
},
575595
]);

client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ export const timeRangeControl = (function () {
251251
const childrenMap = {
252252
start: stringExposingStateControl("start"),
253253
end: stringExposingStateControl("end"),
254+
...formDataChildren,
254255
...commonChildren,
255256
};
256257

@@ -319,6 +320,8 @@ export const timeRangeControl = (function () {
319320
tooltip: trans("time.formatTip"),
320321
})}
321322
</Section>
323+
324+
<FormDataPropertyView {...children} />
322325

323326
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
324327
<><Section name={sectionNames.validation}>
@@ -472,4 +475,21 @@ TimeRangeComp = withMethodExposing(TimeRangeComp, [
472475
comp.children.end.getView().reset();
473476
},
474477
},
478+
{
479+
method: {
480+
name: "setRange",
481+
params: [],
482+
},
483+
execute: (comp, values) => {
484+
if (values.length !== 1) {
485+
return Promise.reject(trans("formComp.valuesLengthError"));
486+
}
487+
const data = values[0] as { start: string, end: string };
488+
if (typeof data !== "object" || data === null || Array.isArray(data) || !data.hasOwnProperty('start') || !data.hasOwnProperty('end')) {
489+
return Promise.reject(trans("formComp.valueTypeError"));
490+
}
491+
comp.children.start.getView().onChange(data.start);
492+
comp.children.end.getView().onChange(data.end);
493+
},
494+
},
475495
]);

client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
321321
setData(data: JSONObject, initialData?: JSONObject) {
322322
// For the properties, first find in data, then initialData, subcomponent default value (resetValue), empty value (clearValue)
323323
const newData = { ...(initialData ?? this.children.initialData.getView()), ...data };
324+
324325
return this.runMethodOfItems(
325326
{
326327
name: "setValue",
@@ -331,8 +332,19 @@ let FormTmpComp = class extends FormBaseComp implements IForm {
331332
return value !== undefined ? [value as EvalParamType] : undefined;
332333
},
333334
},
335+
{
336+
name: "setRange",
337+
getParams: (t) => {
338+
// use component name when formDataKey is empty
339+
const key = t.children.comp.children.formDataKey?.getView() || t.children.name.getView();
340+
const value = newData[key] ? newData[key] : undefined;
341+
return value !== undefined ? [value as EvalParamType] : undefined;
342+
},
343+
},
334344
{ name: "resetValue" },
335-
{ name: "clearValue" }
345+
{ name: "resetAll" },
346+
{ name: "clearValue" },
347+
{ name: "clearAll" }
336348
);
337349
}
338350
reset() {
@@ -443,10 +455,24 @@ export const FormComp = withExposingConfigs(FormTmpComp, [
443455
func: (input) => {
444456
const data: Record<string, unknown> = {};
445457
Object.entries(input.container).forEach(([name, value]) => {
458+
446459
const exposingValues = value as any;
447460
if (exposingValues?.hasOwnProperty("formDataKey")) {
448461
// use component name when formDataKey is empty
449-
data[exposingValues["formDataKey"] || name] = exposingValues["value"];
462+
let inputValue = exposingValues['value'];
463+
// for timeRange/dateRange we don't have value
464+
// instead we have start and end
465+
if (
466+
!inputValue
467+
&& exposingValues?.hasOwnProperty('start')
468+
&& exposingValues?.hasOwnProperty('end')
469+
) {
470+
inputValue = {
471+
start: exposingValues['start'],
472+
end: exposingValues['end'],
473+
}
474+
}
475+
data[exposingValues["formDataKey"] || name] = inputValue;
450476
}
451477
});
452478
return data;

0 commit comments

Comments
 (0)