-
Notifications
You must be signed in to change notification settings - Fork 10
/
demo.js
65 lines (57 loc) · 1.24 KB
/
demo.js
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
define(function(require){
var Vue = require('vendor/vue-0.11.1'),
validator = require('validator');
Vue.use(validator);
Vue.filter('JSON', function (value) {
return JSON.stringify(value,null, "\t");
});
var App = new Vue({
el: '#app',
data: {
validator: {},
form: {
name: '',
age: null,
check: false,
pattern: '',
email: '',
addresses: [],
addresses2: [],
text: ''
}
},
components: {
test: {
template: '<input type="text" v-model="text" value="">',
compiled: function () {
this.$watch('text', function (value) {
this.$parent.form.text = value;
})
}
}
},
computed: {
isValid: function () {
this.validator;
return Object.keys(this.validator.form).every(function (key) {
return this.validator.form[key].valid;
}.bind(this));
},
isModified: function () {
this.validator;
return Object.keys(this.validator.form).some(function (key) {
return this.validator.form[key].modified;
}.bind(this));
}
},
methods: {
addAddress: function (e) {
this.form.addresses2.push({v:e.target.value});
e.target.value = '';
},
onSave: function () {
alert('form is '+(this.$valid() ? 'VALID' : 'INVALID'));
}
}
});
});