Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit e51bcda

Browse files
committed
feat(fields): added field order sorting
1 parent 0a6257d commit e51bcda

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/components/dynamic-form/DynamicForm.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ export default defineComponent({
151151
}
152152
153153
function mapControls(empty?) {
154-
controls.value =
154+
const controlArray =
155155
Object.entries(props.form?.fields).map(
156156
([key, field]: [string, InputBase]) =>
157157
empty
158158
? ({
159159
...field,
160160
name: key,
161-
value: undefined,
161+
value: null,
162162
dirty: false,
163163
touched: false,
164164
} as FormControl)
@@ -169,6 +169,13 @@ export default defineComponent({
169169
touched: false,
170170
} as FormControl),
171171
) || [];
172+
if (props.form.fieldOrder) {
173+
controls.value = controlArray.sort(
174+
(a: FormControl, b: FormControl) =>
175+
props.form.fieldOrder.indexOf(a.name) -
176+
props.form.fieldOrder.indexOf(b.name),
177+
);
178+
}
172179
}
173180
174181
function resetForm() {

src/components/dynamic-form/form.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import { InputBase } from '@/core/models';
22

33
export interface DynamicForm {
44
id: string;
5-
fields: InputBase<any>[];
5+
fields: InputBase[];
6+
fieldOrder?: string[];
67
}

0 commit comments

Comments
 (0)