This repository was archived by the owner on Jun 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
src/components/dynamic-form Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff 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() {
Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ import { InputBase } from '@/core/models';
22
33export interface DynamicForm {
44 id : string ;
5- fields : InputBase < any > [ ] ;
5+ fields : InputBase [ ] ;
6+ fieldOrder ?: string [ ] ;
67}
You can’t perform that action at this time.
0 commit comments