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 +29
-14
lines changed
src/components/dynamic-form Expand file tree Collapse file tree 2 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ export default defineComponent({
3939 fields: [
4040 new TextInput ({
4141 label: ' Name' ,
42- value: ' Awiwi' ,
4342 }),
4443 new EmailInput ({
4544 label: ' Email' ,
@@ -67,12 +66,12 @@ export default defineComponent({
6766 function handleSubmit(values ) {
6867 console .log (' Values Submitted' , values );
6968 }
70- onMounted (() =>
69+ /* onMounted(() =>
7170 setTimeout(() => {
7271 form.fields[0].label = 'RockNRoll';
7372 form.fields[0].value = 'James Bond';
7473 }, 2000),
75- );
74+ ); */
7675 return {
7776 title ,
7877 form ,
Original file line number Diff line number Diff line change @@ -47,11 +47,31 @@ export default defineComponent({
4747 const controls: Ref <FormControl <any >[] | undefined > = ref ([]);
4848 const formValues = reactive ({});
4949 const submited = ref (false );
50- watchEffect (() => {
50+
51+ function valueChanged(changedValue : any ) {
52+ Object .assign (formValues , changedValue );
53+ }
54+
55+ function mapControls(empty ? ) {
5156 controls .value =
52- props .form ?.fields ?.map (
53- (field : InputBase <any >) => new FormControl ({ ... field }),
57+ props .form ?.fields ?.map ((field : InputBase <any >) =>
58+ empty
59+ ? new FormControl ({ ... field , value: null })
60+ : new FormControl ({ ... field }),
5461 ) || [];
62+ }
63+
64+ function resetForm() {
65+ mapControls (true );
66+ }
67+
68+ function handleSubmit() {
69+ submited .value = true ;
70+ emit (' submited' , formValues );
71+ resetForm ();
72+ }
73+
74+ function initValues() {
5575 Object .assign (
5676 formValues ,
5777 controls .value
@@ -66,16 +86,12 @@ export default defineComponent({
6686 }, {})
6787 : {},
6888 );
69- });
70-
71- function valueChanged(changedValue : any ) {
72- Object .assign (formValues , changedValue );
7389 }
7490
75- function handleSubmit() {
76- submited . value = true ;
77- emit ( ' submited ' , formValues );
78- }
91+ watchEffect (() => {
92+ mapControls () ;
93+ initValues ( );
94+ });
7995
8096 return {
8197 controls ,
You can’t perform that action at this time.
0 commit comments