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

Commit 4f6bce7

Browse files
committed
feat(next): solved select issues and general reactivity logic
1 parent bca4e7d commit 4f6bce7

File tree

11 files changed

+5187
-3589
lines changed

11 files changed

+5187
-3589
lines changed

dev/vue/App.vue

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
<h1 class="title m-4">{{ title }}</h1>
55
<div class="flex justify-between">
66
<div class="card p-6">
7-
<dynamic-form :form="form" @submited="handleSubmit" />
7+
<dynamic-form
8+
:form="form"
9+
@submited="handleSubmit"
10+
@changed="valueChanged"
11+
/>
812
<button
913
class="btn bg-teal-500 text-white hover:bg-teal-700 mt-4"
1014
submit="true"
@@ -14,34 +18,51 @@
1418
</button>
1519
</div>
1620
<div class="card p-6">
17-
<pre>{{ form }}</pre>
21+
<pre>{{ formValues }}</pre>
1822
</div>
1923
</div>
2024
</div>
2125
</div>
2226
</template>
2327

2428
<script lang="ts">
25-
import { defineComponent, reactive, ref, onMounted, Ref } from 'vue';
29+
import { defineComponent, reactive, ref } from 'vue';
2630
import {
2731
TextInput,
2832
SelectInput,
2933
DynamicForm,
3034
EmailInput,
35+
FormValidation,
36+
PasswordInput,
3137
} from '../../src/index';
38+
import { email, pattern } from '@/core/utils';
3239
3340
export default defineComponent({
3441
name: 'app',
3542
setup() {
3643
const title = ref('Vue Dynamic Forms');
44+
const formValues = reactive({});
3745
const form = reactive<DynamicForm>({
3846
id: 'example-form',
3947
fields: [
4048
new TextInput({
4149
label: 'Name',
50+
value: 'Alvaro',
4251
}),
4352
new EmailInput({
4453
label: 'Email',
54+
validations: [new FormValidation(email, 'Email format is incorrect')],
55+
}),
56+
new PasswordInput({
57+
label: 'Password',
58+
validations: [
59+
new FormValidation(
60+
pattern(
61+
'^(?=.*[a-z])(?=.*[A-Z])(?=.*)(?=.*[#$^+=!*()@%&]).{8,10}$',
62+
),
63+
'Password must contain at least 1 Uppercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10',
64+
),
65+
],
4566
}),
4667
new SelectInput<string>({
4768
label: 'Games',
@@ -66,6 +87,9 @@ export default defineComponent({
6687
function handleSubmit(values) {
6788
console.log('Values Submitted', values);
6889
}
90+
function valueChanged(values) {
91+
Object.assign(formValues, values);
92+
}
6993
/* onMounted(() =>
7094
setTimeout(() => {
7195
form.fields[0].label = 'RockNRoll';
@@ -76,6 +100,8 @@ export default defineComponent({
76100
title,
77101
form,
78102
handleSubmit,
103+
valueChanged,
104+
formValues,
79105
};
80106
},
81107
});

0 commit comments

Comments
 (0)