-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (86 loc) · 3.74 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VueFormulate PoC</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es2015"></script>
<!-- development version, includes helpful console warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@braid/[email protected]/dist/formulate.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@braid/[email protected]/dist/snow.min.css">
</head>
<body>
<div id="app">
<h1>{{ message }}</h1>
<formulate-form
v-model="formValues"
@submit="formSubmit"
> <!-- v-model is not always required. You will receive the form data in the submit event -->
<formulate-input name="name" label="What is your name?" validation="required"></formulate-input>
<formulate-input name="age" label="How old are you?" validation="required|number|max:120"></formulate-input>
<formulate-input
type="group"
name="pets"
:repeatable="true"
label="Pets"
add-label="Add pet"
#default="{ index }"
>
<p>Pet number {{ index }}</p>
<formulate-input name="name" label="Name" validation="required"></formulate-input>
<formulate-input
name="kind"
:options="{
dog: 'Dog',
cat: 'Cat',
bird: 'Bird',
other: 'Other'
}"
type="select"
label="Kind"
></formulate-input>
</formulate-input>
<formulate-input type="submit" label="Send request"></formulate-input>
</formulate-form>
</div>
<script>
Vue.use(VueFormulate);
new Vue({
el: "#app",
data: {
message: "Hello world!",
formValues: {
pets: []
} // v-model is not always required. You will receive the form data in the submit event
},
// define methods under the `methods` object
methods: {
formSubmit(e) {
/* e is a plain object with the form data while this.formValues (mapped v-model) is a managed object that will detect model updates */
console.log("formSubmit", e, this.formValues);
console.log("Let's try async model update!");
setTimeout(() => { // setTimeout is not required, it's just an example
console.log("Async model update now!");
this.formValues.age++; // Increase age
this.message = `Hello ${this.formValues.name}!! It seems it took me a whole year to process your request!!!` ;
console.log("Pets", [...this.formValues.pets].map(p=>({...p})));
// If pets then let one reproduce
if (this.formValues.pets.length > 0) {
let parent = this.formValues.pets[Math.floor(Math.random()*this.formValues.pets.length)]; // Random parent
this.formValues.pets.push({name:parent.name + '.jr', kind:parent.kind});
}
}, 2000);
}
},
mounted() {
this.$nextTick().then(()=>{
// Int groups with 0 items
this.formValues.pets = [];
});
}
});
</script>
</body>
</html>