vueonrails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +70 -0
- data/app/controllers/vue_controller.rb +2 -0
- data/app/helpers/syntax_helper.rb +28 -0
- data/app/views/vue/index.html.erb +1 -0
- data/config/routes.rb +5 -0
- data/lib/generators/generator_templates/packs/index.css +4 -0
- data/lib/generators/generator_templates/packs/index.js +30 -0
- data/lib/generators/generator_templates/packs/index.vue +13 -0
- data/lib/generators/generator_templates/packs/pack.js.erb +18 -0
- data/lib/generators/generator_templates/sfc/single-file-component.vue +45 -0
- data/lib/generators/generator_templates/tests/unit.test.js.erb +17 -0
- data/lib/generators/generator_templates/turbolinks/turbolinks-pack.js.erb +23 -0
- data/lib/generators/options/click.rb +10 -0
- data/lib/generators/options/form.rb +19 -0
- data/lib/generators/options/list.rb +32 -0
- data/lib/generators/options/modal.rb +26 -0
- data/lib/generators/options/seperate.rb +5 -0
- data/lib/generators/options/single.rb +3 -0
- data/lib/generators/options/table.rb +10 -0
- data/lib/generators/options/test.rb +2 -0
- data/lib/generators/options/turbolinks-seperate.rb +5 -0
- data/lib/generators/options/turbolinks-single.rb +3 -0
- data/lib/generators/options/vuex.rb +10 -0
- data/lib/generators/vue/USAGE +17 -0
- data/lib/generators/vue/vue_generator.rb +60 -0
- data/lib/install/Procfile +2 -0
- data/lib/install/config/alias.js +9 -0
- data/lib/install/setup.rb +78 -0
- data/lib/install/spv.rb +20 -0
- data/lib/install/test.rb +46 -0
- data/lib/install/turbolinks.rb +3 -0
- data/lib/install/ui.rb +4 -0
- data/lib/install/vuex.rb +12 -0
- data/lib/tasks/assets.rake +12 -0
- data/lib/tasks/info.rake +21 -0
- data/lib/tasks/vue.rake +27 -0
- data/lib/vueonrails.rb +13 -0
- data/lib/vueonrails/post_message.rb +4 -0
- data/lib/vueonrails/version.rb +3 -0
- data/vendor/assets/javascripts/axios.js +1545 -0
- data/vendor/assets/javascripts/axios.map +1 -0
- data/vendor/assets/javascripts/element-ui.js +12 -0
- data/vendor/assets/javascripts/vue-resource.js +1531 -0
- data/vendor/assets/javascripts/vue-router.js +2709 -0
- data/vendor/assets/javascripts/vue-router2.js +2284 -0
- data/vendor/assets/javascripts/vue-validator.js +910 -0
- data/vendor/assets/javascripts/vue-validator2.js +2615 -0
- data/vendor/assets/javascripts/vue-validator3.js +2054 -0
- data/vendor/assets/javascripts/vue.js +10237 -0
- data/vendor/assets/javascripts/vue.min.js +9 -0
- data/vendor/assets/javascripts/vue2.js +8568 -0
- data/vendor/assets/javascripts/vue2.min.js +8 -0
- data/vendor/assets/javascripts/vueonrails.js +39 -0
- data/vendor/assets/javascripts/vuex.js +722 -0
- data/vendor/assets/javascripts/vuex2.js +805 -0
- data/vendor/assets/stylesheets/element-ui.css +1 -0
- metadata +128 -0
@@ -0,0 +1,2615 @@
|
|
1
|
+
/*!
|
2
|
+
* vue-validator v2.1.7
|
3
|
+
* (c) 2016 kazuya kawaguchi
|
4
|
+
* Released under the MIT License.
|
5
|
+
*/
|
6
|
+
(function (global, factory) {
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
8
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
9
|
+
(global.VueValidator = factory());
|
10
|
+
}(this, function () { 'use strict';
|
11
|
+
|
12
|
+
var babelHelpers = {};
|
13
|
+
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
14
|
+
return typeof obj;
|
15
|
+
} : function (obj) {
|
16
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
17
|
+
};
|
18
|
+
|
19
|
+
babelHelpers.classCallCheck = function (instance, Constructor) {
|
20
|
+
if (!(instance instanceof Constructor)) {
|
21
|
+
throw new TypeError("Cannot call a class as a function");
|
22
|
+
}
|
23
|
+
};
|
24
|
+
|
25
|
+
babelHelpers.createClass = function () {
|
26
|
+
function defineProperties(target, props) {
|
27
|
+
for (var i = 0; i < props.length; i++) {
|
28
|
+
var descriptor = props[i];
|
29
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
30
|
+
descriptor.configurable = true;
|
31
|
+
if ("value" in descriptor) descriptor.writable = true;
|
32
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
return function (Constructor, protoProps, staticProps) {
|
37
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
38
|
+
if (staticProps) defineProperties(Constructor, staticProps);
|
39
|
+
return Constructor;
|
40
|
+
};
|
41
|
+
}();
|
42
|
+
|
43
|
+
babelHelpers.inherits = function (subClass, superClass) {
|
44
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
45
|
+
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
46
|
+
}
|
47
|
+
|
48
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
49
|
+
constructor: {
|
50
|
+
value: subClass,
|
51
|
+
enumerable: false,
|
52
|
+
writable: true,
|
53
|
+
configurable: true
|
54
|
+
}
|
55
|
+
});
|
56
|
+
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
57
|
+
};
|
58
|
+
|
59
|
+
babelHelpers.possibleConstructorReturn = function (self, call) {
|
60
|
+
if (!self) {
|
61
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
62
|
+
}
|
63
|
+
|
64
|
+
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
65
|
+
};
|
66
|
+
|
67
|
+
babelHelpers;
|
68
|
+
/**
|
69
|
+
* Utilties
|
70
|
+
*/
|
71
|
+
|
72
|
+
// export default for holding the Vue reference
|
73
|
+
var exports$1 = {};
|
74
|
+
/**
|
75
|
+
* warn
|
76
|
+
*
|
77
|
+
* @param {String} msg
|
78
|
+
* @param {Error} [err]
|
79
|
+
*
|
80
|
+
*/
|
81
|
+
|
82
|
+
function warn(msg, err) {
|
83
|
+
if (window.console) {
|
84
|
+
console.warn('[vue-validator] ' + msg);
|
85
|
+
if (err) {
|
86
|
+
console.warn(err.stack);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* empty
|
93
|
+
*
|
94
|
+
* @param {Array|Object} target
|
95
|
+
* @return {Boolean}
|
96
|
+
*/
|
97
|
+
|
98
|
+
function empty(target) {
|
99
|
+
if (target === null || target === undefined) {
|
100
|
+
return true;
|
101
|
+
}
|
102
|
+
|
103
|
+
if (Array.isArray(target)) {
|
104
|
+
if (target.length > 0) {
|
105
|
+
return false;
|
106
|
+
}
|
107
|
+
if (target.length === 0) {
|
108
|
+
return true;
|
109
|
+
}
|
110
|
+
} else if (exports$1.Vue.util.isPlainObject(target)) {
|
111
|
+
for (var key in target) {
|
112
|
+
if (exports$1.Vue.util.hasOwn(target, key)) {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
return true;
|
119
|
+
}
|
120
|
+
|
121
|
+
/**
|
122
|
+
* each
|
123
|
+
*
|
124
|
+
* @param {Array|Object} target
|
125
|
+
* @param {Function} iterator
|
126
|
+
* @param {Object} [context]
|
127
|
+
*/
|
128
|
+
|
129
|
+
function each(target, iterator, context) {
|
130
|
+
if (Array.isArray(target)) {
|
131
|
+
for (var i = 0; i < target.length; i++) {
|
132
|
+
iterator.call(context || target[i], target[i], i);
|
133
|
+
}
|
134
|
+
} else if (exports$1.Vue.util.isPlainObject(target)) {
|
135
|
+
var hasOwn = exports$1.Vue.util.hasOwn;
|
136
|
+
for (var key in target) {
|
137
|
+
if (hasOwn(target, key)) {
|
138
|
+
iterator.call(context || target[key], target[key], key);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
/**
|
145
|
+
* pull
|
146
|
+
*
|
147
|
+
* @param {Array} arr
|
148
|
+
* @param {Object} item
|
149
|
+
* @return {Object|null}
|
150
|
+
*/
|
151
|
+
|
152
|
+
function pull(arr, item) {
|
153
|
+
var index = exports$1.Vue.util.indexOf(arr, item);
|
154
|
+
return ~index ? arr.splice(index, 1) : null;
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* trigger
|
159
|
+
*
|
160
|
+
* @param {Element} el
|
161
|
+
* @param {String} event
|
162
|
+
* @param {Object} [args]
|
163
|
+
*/
|
164
|
+
|
165
|
+
function trigger(el, event, args) {
|
166
|
+
var e = document.createEvent('HTMLEvents');
|
167
|
+
e.initEvent(event, true, false);
|
168
|
+
|
169
|
+
if (args) {
|
170
|
+
for (var prop in args) {
|
171
|
+
e[prop] = args[prop];
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
// Due to Firefox bug, events fired on disabled
|
176
|
+
// non-attached form controls can throw errors
|
177
|
+
try {
|
178
|
+
el.dispatchEvent(e);
|
179
|
+
} catch (e) {}
|
180
|
+
}
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Forgiving check for a promise
|
184
|
+
*
|
185
|
+
* @param {Object} p
|
186
|
+
* @return {Boolean}
|
187
|
+
*/
|
188
|
+
|
189
|
+
function isPromise(p) {
|
190
|
+
return p && typeof p.then === 'function';
|
191
|
+
}
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Togging classes
|
195
|
+
*
|
196
|
+
* @param {Element} el
|
197
|
+
* @param {String} key
|
198
|
+
* @param {Function} fn
|
199
|
+
*/
|
200
|
+
|
201
|
+
function toggleClasses(el, key, fn) {
|
202
|
+
key = key.trim();
|
203
|
+
if (key.indexOf(' ') === -1) {
|
204
|
+
fn(el, key);
|
205
|
+
return;
|
206
|
+
}
|
207
|
+
|
208
|
+
var keys = key.split(/\s+/);
|
209
|
+
for (var i = 0, l = keys.length; i < l; i++) {
|
210
|
+
fn(el, keys[i]);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Fundamental validate functions
|
216
|
+
*/
|
217
|
+
|
218
|
+
/**
|
219
|
+
* required
|
220
|
+
*
|
221
|
+
* This function validate whether the value has been filled out.
|
222
|
+
*
|
223
|
+
* @param {*} val
|
224
|
+
* @return {Boolean}
|
225
|
+
*/
|
226
|
+
|
227
|
+
function required(val) {
|
228
|
+
if (Array.isArray(val)) {
|
229
|
+
if (val.length !== 0) {
|
230
|
+
var valid = true;
|
231
|
+
for (var i = 0, l = val.length; i < l; i++) {
|
232
|
+
valid = required(val[i]);
|
233
|
+
if (!valid) {
|
234
|
+
break;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
return valid;
|
238
|
+
} else {
|
239
|
+
return false;
|
240
|
+
}
|
241
|
+
} else if (typeof val === 'number' || typeof val === 'function') {
|
242
|
+
return true;
|
243
|
+
} else if (typeof val === 'boolean') {
|
244
|
+
return val;
|
245
|
+
} else if (typeof val === 'string') {
|
246
|
+
return val.length > 0;
|
247
|
+
} else if (val !== null && (typeof val === 'undefined' ? 'undefined' : babelHelpers.typeof(val)) === 'object') {
|
248
|
+
return Object.keys(val).length > 0;
|
249
|
+
} else if (val === null || val === undefined) {
|
250
|
+
return false;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* pattern
|
256
|
+
*
|
257
|
+
* This function validate whether the value matches the regex pattern
|
258
|
+
*
|
259
|
+
* @param val
|
260
|
+
* @param {String} pat
|
261
|
+
* @return {Boolean}
|
262
|
+
*/
|
263
|
+
|
264
|
+
function pattern(val, pat) {
|
265
|
+
if (typeof pat !== 'string') {
|
266
|
+
return false;
|
267
|
+
}
|
268
|
+
|
269
|
+
var match = pat.match(new RegExp('^/(.*?)/([gimy]*)$'));
|
270
|
+
if (!match) {
|
271
|
+
return false;
|
272
|
+
}
|
273
|
+
|
274
|
+
return new RegExp(match[1], match[2]).test(val);
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
* minlength
|
279
|
+
*
|
280
|
+
* This function validate whether the minimum length.
|
281
|
+
*
|
282
|
+
* @param {String|Array} val
|
283
|
+
* @param {String|Number} min
|
284
|
+
* @return {Boolean}
|
285
|
+
*/
|
286
|
+
|
287
|
+
function minlength(val, min) {
|
288
|
+
if (typeof val === 'string') {
|
289
|
+
return isInteger(min, 10) && val.length >= parseInt(min, 10);
|
290
|
+
} else if (Array.isArray(val)) {
|
291
|
+
return val.length >= parseInt(min, 10);
|
292
|
+
} else {
|
293
|
+
return false;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
* maxlength
|
299
|
+
*
|
300
|
+
* This function validate whether the maximum length.
|
301
|
+
*
|
302
|
+
* @param {String|Array} val
|
303
|
+
* @param {String|Number} max
|
304
|
+
* @return {Boolean}
|
305
|
+
*/
|
306
|
+
|
307
|
+
function maxlength(val, max) {
|
308
|
+
if (typeof val === 'string') {
|
309
|
+
return isInteger(max, 10) && val.length <= parseInt(max, 10);
|
310
|
+
} else if (Array.isArray(val)) {
|
311
|
+
return val.length <= parseInt(max, 10);
|
312
|
+
} else {
|
313
|
+
return false;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
/**
|
318
|
+
* min
|
319
|
+
*
|
320
|
+
* This function validate whether the minimum value of the numberable value.
|
321
|
+
*
|
322
|
+
* @param {*} val
|
323
|
+
* @param {*} arg minimum
|
324
|
+
* @return {Boolean}
|
325
|
+
*/
|
326
|
+
|
327
|
+
function min(val, arg) {
|
328
|
+
return !isNaN(+val) && !isNaN(+arg) && +val >= +arg;
|
329
|
+
}
|
330
|
+
|
331
|
+
/**
|
332
|
+
* max
|
333
|
+
*
|
334
|
+
* This function validate whether the maximum value of the numberable value.
|
335
|
+
*
|
336
|
+
* @param {*} val
|
337
|
+
* @param {*} arg maximum
|
338
|
+
* @return {Boolean}
|
339
|
+
*/
|
340
|
+
|
341
|
+
function max(val, arg) {
|
342
|
+
return !isNaN(+val) && !isNaN(+arg) && +val <= +arg;
|
343
|
+
}
|
344
|
+
|
345
|
+
/**
|
346
|
+
* isInteger
|
347
|
+
*
|
348
|
+
* This function check whether the value of the string is integer.
|
349
|
+
*
|
350
|
+
* @param {String} val
|
351
|
+
* @return {Boolean}
|
352
|
+
* @private
|
353
|
+
*/
|
354
|
+
|
355
|
+
function isInteger(val) {
|
356
|
+
return (/^(-?[1-9]\d*|0)$/.test(val)
|
357
|
+
);
|
358
|
+
}
|
359
|
+
|
360
|
+
var validators = Object.freeze({
|
361
|
+
required: required,
|
362
|
+
pattern: pattern,
|
363
|
+
minlength: minlength,
|
364
|
+
maxlength: maxlength,
|
365
|
+
min: min,
|
366
|
+
max: max
|
367
|
+
});
|
368
|
+
|
369
|
+
function Asset (Vue) {
|
370
|
+
var extend = Vue.util.extend;
|
371
|
+
|
372
|
+
// set global validators asset
|
373
|
+
var assets = Object.create(null);
|
374
|
+
extend(assets, validators);
|
375
|
+
Vue.options.validators = assets;
|
376
|
+
|
377
|
+
// set option merge strategy
|
378
|
+
var strats = Vue.config.optionMergeStrategies;
|
379
|
+
if (strats) {
|
380
|
+
strats.validators = function (parent, child) {
|
381
|
+
if (!child) {
|
382
|
+
return parent;
|
383
|
+
}
|
384
|
+
if (!parent) {
|
385
|
+
return child;
|
386
|
+
}
|
387
|
+
var ret = Object.create(null);
|
388
|
+
extend(ret, parent);
|
389
|
+
for (var key in child) {
|
390
|
+
ret[key] = child[key];
|
391
|
+
}
|
392
|
+
return ret;
|
393
|
+
};
|
394
|
+
}
|
395
|
+
|
396
|
+
/**
|
397
|
+
* Register or retrieve a global validator definition.
|
398
|
+
*
|
399
|
+
* @param {String} id
|
400
|
+
* @param {Function} definition
|
401
|
+
*/
|
402
|
+
|
403
|
+
Vue.validator = function (id, definition) {
|
404
|
+
if (!definition) {
|
405
|
+
return Vue.options['validators'][id];
|
406
|
+
} else {
|
407
|
+
Vue.options['validators'][id] = definition;
|
408
|
+
}
|
409
|
+
};
|
410
|
+
}
|
411
|
+
|
412
|
+
function Override (Vue) {
|
413
|
+
// override _init
|
414
|
+
var init = Vue.prototype._init;
|
415
|
+
Vue.prototype._init = function (options) {
|
416
|
+
if (!this._validatorMaps) {
|
417
|
+
this._validatorMaps = Object.create(null);
|
418
|
+
}
|
419
|
+
init.call(this, options);
|
420
|
+
};
|
421
|
+
|
422
|
+
// override _destroy
|
423
|
+
var destroy = Vue.prototype._destroy;
|
424
|
+
Vue.prototype._destroy = function () {
|
425
|
+
destroy.apply(this, arguments);
|
426
|
+
this._validatorMaps = null;
|
427
|
+
};
|
428
|
+
}
|
429
|
+
|
430
|
+
var VALIDATE_UPDATE = '__vue-validator-validate-update__';
|
431
|
+
var PRIORITY_VALIDATE = 4096;
|
432
|
+
var PRIORITY_VALIDATE_CLASS = 32;
|
433
|
+
var REGEX_FILTER = /[^|]\|[^|]/;
|
434
|
+
var REGEX_VALIDATE_DIRECTIVE = /^v-validate(?:$|:(.*)$)/;
|
435
|
+
var REGEX_EVENT = /^v-on:|^@/;
|
436
|
+
|
437
|
+
var classId = 0; // ID for validation class
|
438
|
+
|
439
|
+
|
440
|
+
function ValidateClass (Vue) {
|
441
|
+
var vIf = Vue.directive('if');
|
442
|
+
var FragmentFactory = Vue.FragmentFactory;
|
443
|
+
var _Vue$util = Vue.util;
|
444
|
+
var toArray = _Vue$util.toArray;
|
445
|
+
var replace = _Vue$util.replace;
|
446
|
+
var createAnchor = _Vue$util.createAnchor;
|
447
|
+
|
448
|
+
/**
|
449
|
+
* `v-validate-class` directive
|
450
|
+
*/
|
451
|
+
|
452
|
+
Vue.directive('validate-class', {
|
453
|
+
terminal: true,
|
454
|
+
priority: vIf.priority + PRIORITY_VALIDATE_CLASS,
|
455
|
+
|
456
|
+
bind: function bind() {
|
457
|
+
var _this = this;
|
458
|
+
|
459
|
+
var id = String(classId++);
|
460
|
+
this.setClassIds(this.el, id);
|
461
|
+
|
462
|
+
this.vm.$on(VALIDATE_UPDATE, this.cb = function (classIds, validation, results) {
|
463
|
+
if (classIds.indexOf(id) > -1) {
|
464
|
+
validation.updateClasses(results, _this.frag.node);
|
465
|
+
}
|
466
|
+
});
|
467
|
+
|
468
|
+
this.setupFragment();
|
469
|
+
},
|
470
|
+
unbind: function unbind() {
|
471
|
+
this.vm.$off(VALIDATE_UPDATE, this.cb);
|
472
|
+
this.teardownFragment();
|
473
|
+
},
|
474
|
+
setClassIds: function setClassIds(el, id) {
|
475
|
+
var childNodes = toArray(el.childNodes);
|
476
|
+
for (var i = 0, l = childNodes.length; i < l; i++) {
|
477
|
+
var element = childNodes[i];
|
478
|
+
if (element.nodeType === 1) {
|
479
|
+
var hasAttrs = element.hasAttributes();
|
480
|
+
var attrs = hasAttrs && toArray(element.attributes);
|
481
|
+
for (var k = 0, _l = attrs.length; k < _l; k++) {
|
482
|
+
var attr = attrs[k];
|
483
|
+
if (attr.name.match(REGEX_VALIDATE_DIRECTIVE)) {
|
484
|
+
var existingId = element.getAttribute(VALIDATE_UPDATE);
|
485
|
+
var value = existingId ? existingId + ',' + id : id;
|
486
|
+
element.setAttribute(VALIDATE_UPDATE, value);
|
487
|
+
}
|
488
|
+
}
|
489
|
+
}
|
490
|
+
|
491
|
+
if (element.hasChildNodes()) {
|
492
|
+
this.setClassIds(element, id);
|
493
|
+
}
|
494
|
+
}
|
495
|
+
},
|
496
|
+
setupFragment: function setupFragment() {
|
497
|
+
this.anchor = createAnchor('v-validate-class');
|
498
|
+
replace(this.el, this.anchor);
|
499
|
+
|
500
|
+
this.factory = new FragmentFactory(this.vm, this.el);
|
501
|
+
this.frag = this.factory.create(this._host, this._scope, this._frag);
|
502
|
+
this.frag.before(this.anchor);
|
503
|
+
},
|
504
|
+
teardownFragment: function teardownFragment() {
|
505
|
+
if (this.frag) {
|
506
|
+
this.frag.remove();
|
507
|
+
this.frag = null;
|
508
|
+
this.factory = null;
|
509
|
+
}
|
510
|
+
|
511
|
+
replace(this.anchor, this.el);
|
512
|
+
this.anchor = null;
|
513
|
+
}
|
514
|
+
});
|
515
|
+
}
|
516
|
+
|
517
|
+
function Validate (Vue) {
|
518
|
+
var FragmentFactory = Vue.FragmentFactory;
|
519
|
+
var parseDirective = Vue.parsers.directive.parseDirective;
|
520
|
+
var _Vue$util = Vue.util;
|
521
|
+
var inBrowser = _Vue$util.inBrowser;
|
522
|
+
var bind = _Vue$util.bind;
|
523
|
+
var on = _Vue$util.on;
|
524
|
+
var off = _Vue$util.off;
|
525
|
+
var createAnchor = _Vue$util.createAnchor;
|
526
|
+
var replace = _Vue$util.replace;
|
527
|
+
var camelize = _Vue$util.camelize;
|
528
|
+
var isPlainObject = _Vue$util.isPlainObject;
|
529
|
+
|
530
|
+
// Test for IE10/11 textarea placeholder clone bug
|
531
|
+
|
532
|
+
function checkTextareaCloneBug() {
|
533
|
+
if (inBrowser) {
|
534
|
+
var t = document.createElement('textarea');
|
535
|
+
t.placeholder = 't';
|
536
|
+
return t.cloneNode(true).value === 't';
|
537
|
+
} else {
|
538
|
+
return false;
|
539
|
+
}
|
540
|
+
}
|
541
|
+
var hasTextareaCloneBug = checkTextareaCloneBug();
|
542
|
+
|
543
|
+
/**
|
544
|
+
* `v-validate` directive
|
545
|
+
*/
|
546
|
+
|
547
|
+
Vue.directive('validate', {
|
548
|
+
deep: true,
|
549
|
+
terminal: true,
|
550
|
+
priority: PRIORITY_VALIDATE,
|
551
|
+
params: ['group', 'field', 'detect-blur', 'detect-change', 'initial', 'classes'],
|
552
|
+
|
553
|
+
paramWatchers: {
|
554
|
+
detectBlur: function detectBlur(val, old) {
|
555
|
+
if (this._invalid) {
|
556
|
+
return;
|
557
|
+
}
|
558
|
+
this.validation.detectBlur = this.isDetectBlur(val);
|
559
|
+
this.validator.validate(this.field);
|
560
|
+
},
|
561
|
+
detectChange: function detectChange(val, old) {
|
562
|
+
if (this._invalid) {
|
563
|
+
return;
|
564
|
+
}
|
565
|
+
this.validation.detectChange = this.isDetectChange(val);
|
566
|
+
this.validator.validate(this.field);
|
567
|
+
}
|
568
|
+
},
|
569
|
+
|
570
|
+
bind: function bind() {
|
571
|
+
var el = this.el;
|
572
|
+
|
573
|
+
if ('development' !== 'production' && el.__vue__) {
|
574
|
+
warn('v-validate="' + this.expression + '" cannot be used on an instance root element.');
|
575
|
+
this._invalid = true;
|
576
|
+
return;
|
577
|
+
}
|
578
|
+
|
579
|
+
if ('development' !== 'production' && (el.hasAttribute('v-if') || el.hasAttribute('v-for'))) {
|
580
|
+
warn('v-validate cannot be used `v-if` or `v-for` build-in terminal directive ' + 'on an element. these is wrapped with `<template>` or other tags: ' + '(e.g. <validator name="validator">' + '<template v-if="hidden">' + '<input type="text" v-validate:field1="[\'required\']">' + '</template>' + '</validator>).');
|
581
|
+
this._invalid = true;
|
582
|
+
return;
|
583
|
+
}
|
584
|
+
|
585
|
+
if ('development' !== 'production' && !(this.arg || this.params.field)) {
|
586
|
+
warn('you need specify field name for v-validate directive.');
|
587
|
+
this._invalid = true;
|
588
|
+
return;
|
589
|
+
}
|
590
|
+
|
591
|
+
var validatorName = this.vm.$options._validator;
|
592
|
+
if ('development' !== 'production' && !validatorName) {
|
593
|
+
warn('you need to wrap the elements to be validated in a <validator> element: ' + '(e.g. <validator name="validator">' + '<input type="text" v-validate:field1="[\'required\']">' + '</validator>).');
|
594
|
+
this._invalid = true;
|
595
|
+
return;
|
596
|
+
}
|
597
|
+
|
598
|
+
var raw = el.getAttribute('v-model');
|
599
|
+
|
600
|
+
var _parseModelRaw = this.parseModelRaw(raw);
|
601
|
+
|
602
|
+
var model = _parseModelRaw.model;
|
603
|
+
var filters = _parseModelRaw.filters;
|
604
|
+
|
605
|
+
this.model = model;
|
606
|
+
|
607
|
+
this.setupFragment();
|
608
|
+
this.setupValidate(validatorName, model, filters);
|
609
|
+
this.listen();
|
610
|
+
},
|
611
|
+
update: function update(value, old) {
|
612
|
+
if (!value || this._invalid) {
|
613
|
+
return;
|
614
|
+
}
|
615
|
+
|
616
|
+
if (isPlainObject(value) || old && isPlainObject(old)) {
|
617
|
+
this.handleObject(value, old, this.params.initial);
|
618
|
+
} else if (Array.isArray(value) || old && Array.isArray(old)) {
|
619
|
+
this.handleArray(value, old, this.params.initial);
|
620
|
+
}
|
621
|
+
|
622
|
+
var options = { field: this.field };
|
623
|
+
if (this.frag) {
|
624
|
+
options.el = this.frag.node;
|
625
|
+
}
|
626
|
+
this.validator.validate(options);
|
627
|
+
},
|
628
|
+
unbind: function unbind() {
|
629
|
+
if (this._invalid) {
|
630
|
+
return;
|
631
|
+
}
|
632
|
+
|
633
|
+
this.unlisten();
|
634
|
+
this.teardownValidate();
|
635
|
+
this.teardownFragment();
|
636
|
+
|
637
|
+
this.model = null;
|
638
|
+
},
|
639
|
+
parseModelRaw: function parseModelRaw(raw) {
|
640
|
+
if (REGEX_FILTER.test(raw)) {
|
641
|
+
var parsed = parseDirective(raw);
|
642
|
+
return { model: parsed.expression, filters: parsed.filters };
|
643
|
+
} else {
|
644
|
+
return { model: raw };
|
645
|
+
}
|
646
|
+
},
|
647
|
+
setupValidate: function setupValidate(name, model, filters) {
|
648
|
+
var params = this.params;
|
649
|
+
var validator = this.validator = this.vm._validatorMaps[name];
|
650
|
+
|
651
|
+
this.field = camelize(this.arg ? this.arg : params.field);
|
652
|
+
|
653
|
+
this.validation = validator.manageValidation(this.field, model, this.vm, this.getElementFrom(this.frag), this._scope, filters, params.initial, this.isDetectBlur(params.detectBlur), this.isDetectChange(params.detectChange));
|
654
|
+
|
655
|
+
isPlainObject(params.classes) && this.validation.setValidationClasses(params.classes);
|
656
|
+
|
657
|
+
params.group && validator.addGroupValidation(params.group, this.field);
|
658
|
+
},
|
659
|
+
listen: function listen() {
|
660
|
+
var model = this.model;
|
661
|
+
var validation = this.validation;
|
662
|
+
var el = this.getElementFrom(this.frag);
|
663
|
+
|
664
|
+
this.onBlur = bind(validation.listener, validation);
|
665
|
+
on(el, 'blur', this.onBlur);
|
666
|
+
if ((el.type === 'radio' || el.tagName === 'SELECT') && !model) {
|
667
|
+
this.onChange = bind(validation.listener, validation);
|
668
|
+
on(el, 'change', this.onChange);
|
669
|
+
} else if (el.type === 'checkbox') {
|
670
|
+
if (!model) {
|
671
|
+
this.onChange = bind(validation.listener, validation);
|
672
|
+
on(el, 'change', this.onChange);
|
673
|
+
} else {
|
674
|
+
this.onClick = bind(validation.listener, validation);
|
675
|
+
on(el, 'click', this.onClick);
|
676
|
+
}
|
677
|
+
} else {
|
678
|
+
if (!model) {
|
679
|
+
this.onInput = bind(validation.listener, validation);
|
680
|
+
on(el, 'input', this.onInput);
|
681
|
+
}
|
682
|
+
}
|
683
|
+
},
|
684
|
+
unlisten: function unlisten() {
|
685
|
+
var el = this.getElementFrom(this.frag);
|
686
|
+
|
687
|
+
if (this.onInput) {
|
688
|
+
off(el, 'input', this.onInput);
|
689
|
+
this.onInput = null;
|
690
|
+
}
|
691
|
+
|
692
|
+
if (this.onClick) {
|
693
|
+
off(el, 'click', this.onClick);
|
694
|
+
this.onClick = null;
|
695
|
+
}
|
696
|
+
|
697
|
+
if (this.onChange) {
|
698
|
+
off(el, 'change', this.onChange);
|
699
|
+
this.onChange = null;
|
700
|
+
}
|
701
|
+
|
702
|
+
if (this.onBlur) {
|
703
|
+
off(el, 'blur', this.onBlur);
|
704
|
+
this.onBlur = null;
|
705
|
+
}
|
706
|
+
},
|
707
|
+
teardownValidate: function teardownValidate() {
|
708
|
+
if (this.validator && this.validation) {
|
709
|
+
var el = this.getElementFrom(this.frag);
|
710
|
+
|
711
|
+
this.params.group && this.validator.removeGroupValidation(this.params.group, this.field);
|
712
|
+
|
713
|
+
this.validator.unmanageValidation(this.field, el);
|
714
|
+
|
715
|
+
this.validator = null;
|
716
|
+
this.validation = null;
|
717
|
+
this.field = null;
|
718
|
+
}
|
719
|
+
},
|
720
|
+
setupFragment: function setupFragment() {
|
721
|
+
this.anchor = createAnchor('v-validate');
|
722
|
+
replace(this.el, this.anchor);
|
723
|
+
|
724
|
+
this.factory = new FragmentFactory(this.vm, this.shimNode(this.el));
|
725
|
+
this.frag = this.factory.create(this._host, this._scope, this._frag);
|
726
|
+
this.frag.before(this.anchor);
|
727
|
+
},
|
728
|
+
teardownFragment: function teardownFragment() {
|
729
|
+
if (this.frag) {
|
730
|
+
this.frag.remove();
|
731
|
+
this.frag = null;
|
732
|
+
this.factory = null;
|
733
|
+
}
|
734
|
+
|
735
|
+
replace(this.anchor, this.el);
|
736
|
+
this.anchor = null;
|
737
|
+
},
|
738
|
+
handleArray: function handleArray(value, old, initial) {
|
739
|
+
var _this = this;
|
740
|
+
|
741
|
+
old && this.validation.resetValidation();
|
742
|
+
|
743
|
+
each(value, function (val) {
|
744
|
+
_this.validation.setValidation(val, undefined, undefined, initial);
|
745
|
+
});
|
746
|
+
},
|
747
|
+
handleObject: function handleObject(value, old, initial) {
|
748
|
+
var _this2 = this;
|
749
|
+
|
750
|
+
old && this.validation.resetValidation();
|
751
|
+
|
752
|
+
each(value, function (val, key) {
|
753
|
+
if (isPlainObject(val)) {
|
754
|
+
if ('rule' in val) {
|
755
|
+
var msg = 'message' in val ? val.message : null;
|
756
|
+
var init = 'initial' in val ? val.initial : null;
|
757
|
+
_this2.validation.setValidation(key, val.rule, msg, init || initial);
|
758
|
+
}
|
759
|
+
} else {
|
760
|
+
_this2.validation.setValidation(key, val, undefined, initial);
|
761
|
+
}
|
762
|
+
});
|
763
|
+
},
|
764
|
+
isDetectBlur: function isDetectBlur(detectBlur) {
|
765
|
+
return detectBlur === undefined || detectBlur === 'on' || detectBlur === true;
|
766
|
+
},
|
767
|
+
isDetectChange: function isDetectChange(detectChange) {
|
768
|
+
return detectChange === undefined || detectChange === 'on' || detectChange === true;
|
769
|
+
},
|
770
|
+
isInitialNoopValidation: function isInitialNoopValidation(initial) {
|
771
|
+
return initial === 'off' || initial === false;
|
772
|
+
},
|
773
|
+
shimNode: function shimNode(node) {
|
774
|
+
var ret = node;
|
775
|
+
if (hasTextareaCloneBug) {
|
776
|
+
if (node.tagName === 'TEXTAREA') {
|
777
|
+
ret = node.cloneNode(true);
|
778
|
+
ret.value = node.value;
|
779
|
+
var i = ret.childNodes.length;
|
780
|
+
while (i--) {
|
781
|
+
ret.removeChild(ret.childNodes[i]);
|
782
|
+
}
|
783
|
+
}
|
784
|
+
}
|
785
|
+
return ret;
|
786
|
+
},
|
787
|
+
getElementFrom: function getElementFrom(frag) {
|
788
|
+
return frag.single ? frag.node : frag.node.nextSibling;
|
789
|
+
}
|
790
|
+
});
|
791
|
+
}
|
792
|
+
|
793
|
+
/**
|
794
|
+
* BaseValidation class
|
795
|
+
*/
|
796
|
+
|
797
|
+
var BaseValidation = function () {
|
798
|
+
function BaseValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) {
|
799
|
+
babelHelpers.classCallCheck(this, BaseValidation);
|
800
|
+
|
801
|
+
this.field = field;
|
802
|
+
this.touched = false;
|
803
|
+
this.dirty = false;
|
804
|
+
this.modified = false;
|
805
|
+
|
806
|
+
this._modified = false;
|
807
|
+
this._model = model;
|
808
|
+
this._filters = filters;
|
809
|
+
this._validator = validator;
|
810
|
+
this._vm = vm;
|
811
|
+
this._el = el;
|
812
|
+
this._forScope = scope;
|
813
|
+
this._init = this._getValue(el);
|
814
|
+
this._validators = {};
|
815
|
+
this._detectBlur = detectBlur;
|
816
|
+
this._detectChange = detectChange;
|
817
|
+
this._classes = {};
|
818
|
+
}
|
819
|
+
|
820
|
+
BaseValidation.prototype.manageElement = function manageElement(el, initial) {
|
821
|
+
var _this = this;
|
822
|
+
|
823
|
+
var scope = this._getScope();
|
824
|
+
var model = this._model;
|
825
|
+
|
826
|
+
this._initial = initial;
|
827
|
+
|
828
|
+
var classIds = el.getAttribute(VALIDATE_UPDATE);
|
829
|
+
if (classIds) {
|
830
|
+
el.removeAttribute(VALIDATE_UPDATE);
|
831
|
+
this._classIds = classIds.split(',');
|
832
|
+
}
|
833
|
+
|
834
|
+
if (model) {
|
835
|
+
el.value = this._evalModel(model, this._filters);
|
836
|
+
this._unwatch = scope.$watch(model, function (val, old) {
|
837
|
+
if (val !== old) {
|
838
|
+
if (_this.guardValidate(el, 'input')) {
|
839
|
+
return;
|
840
|
+
}
|
841
|
+
|
842
|
+
_this.handleValidate(el, { noopable: _this._initial });
|
843
|
+
if (_this._initial) {
|
844
|
+
_this._initial = null;
|
845
|
+
}
|
846
|
+
}
|
847
|
+
}, { deep: true });
|
848
|
+
}
|
849
|
+
};
|
850
|
+
|
851
|
+
BaseValidation.prototype.unmanageElement = function unmanageElement(el) {
|
852
|
+
this._unwatch && this._unwatch();
|
853
|
+
};
|
854
|
+
|
855
|
+
BaseValidation.prototype.resetValidation = function resetValidation() {
|
856
|
+
var _this2 = this;
|
857
|
+
|
858
|
+
var keys = Object.keys(this._validators);
|
859
|
+
each(keys, function (key, index) {
|
860
|
+
_this2._validators[key] = null;
|
861
|
+
delete _this2._validators[key];
|
862
|
+
});
|
863
|
+
};
|
864
|
+
|
865
|
+
BaseValidation.prototype.resetValidationNoopable = function resetValidationNoopable() {
|
866
|
+
each(this._validators, function (descriptor, key) {
|
867
|
+
if (descriptor.initial && !descriptor._isNoopable) {
|
868
|
+
descriptor._isNoopable = true;
|
869
|
+
}
|
870
|
+
});
|
871
|
+
};
|
872
|
+
|
873
|
+
BaseValidation.prototype.setValidation = function setValidation(name, arg, msg, initial) {
|
874
|
+
var validator = this._validators[name];
|
875
|
+
if (!validator) {
|
876
|
+
validator = this._validators[name] = {};
|
877
|
+
validator.name = name;
|
878
|
+
}
|
879
|
+
|
880
|
+
validator.arg = arg;
|
881
|
+
if (msg) {
|
882
|
+
validator.msg = msg;
|
883
|
+
}
|
884
|
+
|
885
|
+
if (initial) {
|
886
|
+
validator.initial = initial;
|
887
|
+
validator._isNoopable = true;
|
888
|
+
}
|
889
|
+
};
|
890
|
+
|
891
|
+
BaseValidation.prototype.setValidationClasses = function setValidationClasses(classes) {
|
892
|
+
var _this3 = this;
|
893
|
+
|
894
|
+
each(classes, function (value, key) {
|
895
|
+
_this3._classes[key] = value;
|
896
|
+
});
|
897
|
+
};
|
898
|
+
|
899
|
+
BaseValidation.prototype.willUpdateFlags = function willUpdateFlags() {
|
900
|
+
var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
|
901
|
+
|
902
|
+
touched && this.willUpdateTouched(this._el, 'blur');
|
903
|
+
this.willUpdateDirty(this._el);
|
904
|
+
this.willUpdateModified(this._el);
|
905
|
+
};
|
906
|
+
|
907
|
+
BaseValidation.prototype.willUpdateTouched = function willUpdateTouched(el, type) {
|
908
|
+
if (type && type === 'blur') {
|
909
|
+
this.touched = true;
|
910
|
+
this._fireEvent(el, 'touched');
|
911
|
+
}
|
912
|
+
};
|
913
|
+
|
914
|
+
BaseValidation.prototype.willUpdateDirty = function willUpdateDirty(el) {
|
915
|
+
if (!this.dirty && this._checkModified(el)) {
|
916
|
+
this.dirty = true;
|
917
|
+
this._fireEvent(el, 'dirty');
|
918
|
+
}
|
919
|
+
};
|
920
|
+
|
921
|
+
BaseValidation.prototype.willUpdateModified = function willUpdateModified(el) {
|
922
|
+
this.modified = this._checkModified(el);
|
923
|
+
if (this._modified !== this.modified) {
|
924
|
+
this._fireEvent(el, 'modified', { modified: this.modified });
|
925
|
+
this._modified = this.modified;
|
926
|
+
}
|
927
|
+
};
|
928
|
+
|
929
|
+
BaseValidation.prototype.listener = function listener(e) {
|
930
|
+
if (this.guardValidate(e.target, e.type)) {
|
931
|
+
return;
|
932
|
+
}
|
933
|
+
|
934
|
+
this.handleValidate(e.target, { type: e.type });
|
935
|
+
};
|
936
|
+
|
937
|
+
BaseValidation.prototype.handleValidate = function handleValidate(el) {
|
938
|
+
var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
939
|
+
|
940
|
+
var _ref$type = _ref.type;
|
941
|
+
var type = _ref$type === undefined ? null : _ref$type;
|
942
|
+
var _ref$noopable = _ref.noopable;
|
943
|
+
var noopable = _ref$noopable === undefined ? false : _ref$noopable;
|
944
|
+
|
945
|
+
this.willUpdateTouched(el, type);
|
946
|
+
this.willUpdateDirty(el);
|
947
|
+
this.willUpdateModified(el);
|
948
|
+
|
949
|
+
this._validator.validate({ field: this.field, el: el, noopable: noopable });
|
950
|
+
};
|
951
|
+
|
952
|
+
BaseValidation.prototype.validate = function validate(cb) {
|
953
|
+
var _this4 = this;
|
954
|
+
|
955
|
+
var noopable = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
956
|
+
var el = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
|
957
|
+
|
958
|
+
var _ = exports$1.Vue.util;
|
959
|
+
|
960
|
+
var results = {};
|
961
|
+
var errors = [];
|
962
|
+
var valid = true;
|
963
|
+
|
964
|
+
this._runValidators(function (descriptor, name, done) {
|
965
|
+
var asset = _this4._resolveValidator(name);
|
966
|
+
var validator = null;
|
967
|
+
var msg = null;
|
968
|
+
|
969
|
+
if (_.isPlainObject(asset)) {
|
970
|
+
if (asset.check && typeof asset.check === 'function') {
|
971
|
+
validator = asset.check;
|
972
|
+
}
|
973
|
+
if (asset.message) {
|
974
|
+
msg = asset.message;
|
975
|
+
}
|
976
|
+
} else if (typeof asset === 'function') {
|
977
|
+
validator = asset;
|
978
|
+
}
|
979
|
+
|
980
|
+
if (descriptor.msg) {
|
981
|
+
msg = descriptor.msg;
|
982
|
+
}
|
983
|
+
|
984
|
+
if (noopable) {
|
985
|
+
results[name] = false;
|
986
|
+
return done();
|
987
|
+
}
|
988
|
+
|
989
|
+
if (descriptor._isNoopable) {
|
990
|
+
results[name] = false;
|
991
|
+
descriptor._isNoopable = null;
|
992
|
+
return done();
|
993
|
+
}
|
994
|
+
|
995
|
+
if (validator) {
|
996
|
+
var value = _this4._getValue(_this4._el);
|
997
|
+
_this4._invokeValidator(_this4._vm, validator, value, descriptor.arg, function (ret, err) {
|
998
|
+
if (!ret) {
|
999
|
+
valid = false;
|
1000
|
+
if (err) {
|
1001
|
+
// async error message
|
1002
|
+
errors.push({ validator: name, message: err });
|
1003
|
+
results[name] = err;
|
1004
|
+
} else if (msg) {
|
1005
|
+
var error = { validator: name };
|
1006
|
+
error.message = typeof msg === 'function' ? msg.call(_this4._vm, _this4.field, descriptor.arg) : msg;
|
1007
|
+
errors.push(error);
|
1008
|
+
results[name] = error.message;
|
1009
|
+
} else {
|
1010
|
+
results[name] = !ret;
|
1011
|
+
}
|
1012
|
+
} else {
|
1013
|
+
results[name] = !ret;
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
done();
|
1017
|
+
});
|
1018
|
+
} else {
|
1019
|
+
done();
|
1020
|
+
}
|
1021
|
+
}, function () {
|
1022
|
+
// finished
|
1023
|
+
_this4._fireEvent(_this4._el, valid ? 'valid' : 'invalid');
|
1024
|
+
|
1025
|
+
var props = {
|
1026
|
+
valid: valid,
|
1027
|
+
invalid: !valid,
|
1028
|
+
touched: _this4.touched,
|
1029
|
+
untouched: !_this4.touched,
|
1030
|
+
dirty: _this4.dirty,
|
1031
|
+
pristine: !_this4.dirty,
|
1032
|
+
modified: _this4.modified
|
1033
|
+
};
|
1034
|
+
if (!empty(errors)) {
|
1035
|
+
props.errors = errors;
|
1036
|
+
}
|
1037
|
+
_.extend(results, props);
|
1038
|
+
|
1039
|
+
_this4.willUpdateClasses(results, el);
|
1040
|
+
|
1041
|
+
cb(results);
|
1042
|
+
});
|
1043
|
+
};
|
1044
|
+
|
1045
|
+
BaseValidation.prototype.resetFlags = function resetFlags() {
|
1046
|
+
this.touched = false;
|
1047
|
+
this.dirty = false;
|
1048
|
+
this.modified = false;
|
1049
|
+
this._modified = false;
|
1050
|
+
};
|
1051
|
+
|
1052
|
+
BaseValidation.prototype.reset = function reset() {
|
1053
|
+
this.resetValidationNoopable();
|
1054
|
+
this.resetFlags();
|
1055
|
+
this._init = this._getValue(this._el);
|
1056
|
+
};
|
1057
|
+
|
1058
|
+
BaseValidation.prototype.willUpdateClasses = function willUpdateClasses(results) {
|
1059
|
+
var _this5 = this;
|
1060
|
+
|
1061
|
+
var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
|
1062
|
+
|
1063
|
+
if (this._checkClassIds(el)) {
|
1064
|
+
(function () {
|
1065
|
+
var classIds = _this5._getClassIds(el);
|
1066
|
+
_this5.vm.$nextTick(function () {
|
1067
|
+
_this5.vm.$emit(VALIDATE_UPDATE, classIds, _this5, results);
|
1068
|
+
});
|
1069
|
+
})();
|
1070
|
+
} else {
|
1071
|
+
this.updateClasses(results);
|
1072
|
+
}
|
1073
|
+
};
|
1074
|
+
|
1075
|
+
BaseValidation.prototype.updateClasses = function updateClasses(results) {
|
1076
|
+
var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
|
1077
|
+
|
1078
|
+
this._updateClasses(el || this._el, results);
|
1079
|
+
};
|
1080
|
+
|
1081
|
+
BaseValidation.prototype.guardValidate = function guardValidate(el, type) {
|
1082
|
+
if (type && type === 'blur' && !this.detectBlur) {
|
1083
|
+
return true;
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
if (type && type === 'input' && !this.detectChange) {
|
1087
|
+
return true;
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
if (type && type === 'change' && !this.detectChange) {
|
1091
|
+
return true;
|
1092
|
+
}
|
1093
|
+
|
1094
|
+
if (type && type === 'click' && !this.detectChange) {
|
1095
|
+
return true;
|
1096
|
+
}
|
1097
|
+
|
1098
|
+
return false;
|
1099
|
+
};
|
1100
|
+
|
1101
|
+
BaseValidation.prototype._getValue = function _getValue(el) {
|
1102
|
+
return el.value;
|
1103
|
+
};
|
1104
|
+
|
1105
|
+
BaseValidation.prototype._getScope = function _getScope() {
|
1106
|
+
return this._forScope || this._vm;
|
1107
|
+
};
|
1108
|
+
|
1109
|
+
BaseValidation.prototype._getClassIds = function _getClassIds(el) {
|
1110
|
+
return this._classIds;
|
1111
|
+
};
|
1112
|
+
|
1113
|
+
BaseValidation.prototype._checkModified = function _checkModified(target) {
|
1114
|
+
return this._init !== this._getValue(target);
|
1115
|
+
};
|
1116
|
+
|
1117
|
+
BaseValidation.prototype._checkClassIds = function _checkClassIds(el) {
|
1118
|
+
return this._getClassIds(el);
|
1119
|
+
};
|
1120
|
+
|
1121
|
+
BaseValidation.prototype._fireEvent = function _fireEvent(el, type, args) {
|
1122
|
+
trigger(el, type, args);
|
1123
|
+
};
|
1124
|
+
|
1125
|
+
BaseValidation.prototype._evalModel = function _evalModel(model, filters) {
|
1126
|
+
var scope = this._getScope();
|
1127
|
+
|
1128
|
+
var val = null;
|
1129
|
+
if (filters) {
|
1130
|
+
val = scope.$get(model);
|
1131
|
+
return filters ? this._applyFilters(val, null, filters) : val;
|
1132
|
+
} else {
|
1133
|
+
val = scope.$get(model);
|
1134
|
+
return val === undefined || val === null ? '' : val;
|
1135
|
+
}
|
1136
|
+
};
|
1137
|
+
|
1138
|
+
BaseValidation.prototype._updateClasses = function _updateClasses(el, results) {
|
1139
|
+
this._toggleValid(el, results.valid);
|
1140
|
+
this._toggleTouched(el, results.touched);
|
1141
|
+
this._togglePristine(el, results.pristine);
|
1142
|
+
this._toggleModfied(el, results.modified);
|
1143
|
+
};
|
1144
|
+
|
1145
|
+
BaseValidation.prototype._toggleValid = function _toggleValid(el, valid) {
|
1146
|
+
var _util$Vue$util = exports$1.Vue.util;
|
1147
|
+
var addClass = _util$Vue$util.addClass;
|
1148
|
+
var removeClass = _util$Vue$util.removeClass;
|
1149
|
+
|
1150
|
+
var validClass = this._classes.valid || 'valid';
|
1151
|
+
var invalidClass = this._classes.invalid || 'invalid';
|
1152
|
+
|
1153
|
+
if (valid) {
|
1154
|
+
toggleClasses(el, validClass, addClass);
|
1155
|
+
toggleClasses(el, invalidClass, removeClass);
|
1156
|
+
} else {
|
1157
|
+
toggleClasses(el, validClass, removeClass);
|
1158
|
+
toggleClasses(el, invalidClass, addClass);
|
1159
|
+
}
|
1160
|
+
};
|
1161
|
+
|
1162
|
+
BaseValidation.prototype._toggleTouched = function _toggleTouched(el, touched) {
|
1163
|
+
var _util$Vue$util2 = exports$1.Vue.util;
|
1164
|
+
var addClass = _util$Vue$util2.addClass;
|
1165
|
+
var removeClass = _util$Vue$util2.removeClass;
|
1166
|
+
|
1167
|
+
var touchedClass = this._classes.touched || 'touched';
|
1168
|
+
var untouchedClass = this._classes.untouched || 'untouched';
|
1169
|
+
|
1170
|
+
if (touched) {
|
1171
|
+
toggleClasses(el, touchedClass, addClass);
|
1172
|
+
toggleClasses(el, untouchedClass, removeClass);
|
1173
|
+
} else {
|
1174
|
+
toggleClasses(el, touchedClass, removeClass);
|
1175
|
+
toggleClasses(el, untouchedClass, addClass);
|
1176
|
+
}
|
1177
|
+
};
|
1178
|
+
|
1179
|
+
BaseValidation.prototype._togglePristine = function _togglePristine(el, pristine) {
|
1180
|
+
var _util$Vue$util3 = exports$1.Vue.util;
|
1181
|
+
var addClass = _util$Vue$util3.addClass;
|
1182
|
+
var removeClass = _util$Vue$util3.removeClass;
|
1183
|
+
|
1184
|
+
var pristineClass = this._classes.pristine || 'pristine';
|
1185
|
+
var dirtyClass = this._classes.dirty || 'dirty';
|
1186
|
+
|
1187
|
+
if (pristine) {
|
1188
|
+
toggleClasses(el, pristineClass, addClass);
|
1189
|
+
toggleClasses(el, dirtyClass, removeClass);
|
1190
|
+
} else {
|
1191
|
+
toggleClasses(el, pristineClass, removeClass);
|
1192
|
+
toggleClasses(el, dirtyClass, addClass);
|
1193
|
+
}
|
1194
|
+
};
|
1195
|
+
|
1196
|
+
BaseValidation.prototype._toggleModfied = function _toggleModfied(el, modified) {
|
1197
|
+
var _util$Vue$util4 = exports$1.Vue.util;
|
1198
|
+
var addClass = _util$Vue$util4.addClass;
|
1199
|
+
var removeClass = _util$Vue$util4.removeClass;
|
1200
|
+
|
1201
|
+
var modifiedClass = this._classes.modified || 'modified';
|
1202
|
+
|
1203
|
+
if (modified) {
|
1204
|
+
toggleClasses(el, modifiedClass, addClass);
|
1205
|
+
} else {
|
1206
|
+
toggleClasses(el, modifiedClass, removeClass);
|
1207
|
+
}
|
1208
|
+
};
|
1209
|
+
|
1210
|
+
BaseValidation.prototype._applyFilters = function _applyFilters(value, oldValue, filters, write) {
|
1211
|
+
var resolveAsset = exports$1.Vue.util.resolveAsset;
|
1212
|
+
var scope = this._getScope();
|
1213
|
+
|
1214
|
+
var filter = void 0,
|
1215
|
+
fn = void 0,
|
1216
|
+
args = void 0,
|
1217
|
+
arg = void 0,
|
1218
|
+
offset = void 0,
|
1219
|
+
i = void 0,
|
1220
|
+
l = void 0,
|
1221
|
+
j = void 0,
|
1222
|
+
k = void 0;
|
1223
|
+
for (i = 0, l = filters.length; i < l; i++) {
|
1224
|
+
filter = filters[i];
|
1225
|
+
fn = resolveAsset(this._vm.$options, 'filters', filter.name);
|
1226
|
+
if (!fn) {
|
1227
|
+
continue;
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
fn = write ? fn.write : fn.read || fn;
|
1231
|
+
if (typeof fn !== 'function') {
|
1232
|
+
continue;
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
args = write ? [value, oldValue] : [value];
|
1236
|
+
offset = write ? 2 : 1;
|
1237
|
+
if (filter.args) {
|
1238
|
+
for (j = 0, k = filter.args.length; j < k; j++) {
|
1239
|
+
arg = filter.args[j];
|
1240
|
+
args[j + offset] = arg.dynamic ? scope.$get(arg.value) : arg.value;
|
1241
|
+
}
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
value = fn.apply(this._vm, args);
|
1245
|
+
}
|
1246
|
+
|
1247
|
+
return value;
|
1248
|
+
};
|
1249
|
+
|
1250
|
+
BaseValidation.prototype._runValidators = function _runValidators(fn, cb) {
|
1251
|
+
var validators = this._validators;
|
1252
|
+
var length = Object.keys(validators).length;
|
1253
|
+
|
1254
|
+
var count = 0;
|
1255
|
+
each(validators, function (descriptor, name) {
|
1256
|
+
fn(descriptor, name, function () {
|
1257
|
+
++count;
|
1258
|
+
count >= length && cb();
|
1259
|
+
});
|
1260
|
+
});
|
1261
|
+
};
|
1262
|
+
|
1263
|
+
BaseValidation.prototype._invokeValidator = function _invokeValidator(vm, validator, val, arg, cb) {
|
1264
|
+
var future = validator.call(this, val, arg);
|
1265
|
+
if (typeof future === 'function') {
|
1266
|
+
// function
|
1267
|
+
future(function () {
|
1268
|
+
// resolve
|
1269
|
+
cb(true);
|
1270
|
+
}, function (msg) {
|
1271
|
+
// reject
|
1272
|
+
cb(false, msg);
|
1273
|
+
});
|
1274
|
+
} else if (isPromise(future)) {
|
1275
|
+
// promise
|
1276
|
+
future.then(function () {
|
1277
|
+
// resolve
|
1278
|
+
cb(true);
|
1279
|
+
}, function (msg) {
|
1280
|
+
// reject
|
1281
|
+
cb(false, msg);
|
1282
|
+
}).catch(function (err) {
|
1283
|
+
cb(false, err.message);
|
1284
|
+
});
|
1285
|
+
} else {
|
1286
|
+
// sync
|
1287
|
+
cb(future);
|
1288
|
+
}
|
1289
|
+
};
|
1290
|
+
|
1291
|
+
BaseValidation.prototype._resolveValidator = function _resolveValidator(name) {
|
1292
|
+
var resolveAsset = exports$1.Vue.util.resolveAsset;
|
1293
|
+
return resolveAsset(this._vm.$options, 'validators', name);
|
1294
|
+
};
|
1295
|
+
|
1296
|
+
babelHelpers.createClass(BaseValidation, [{
|
1297
|
+
key: 'vm',
|
1298
|
+
get: function get() {
|
1299
|
+
return this._vm;
|
1300
|
+
}
|
1301
|
+
}, {
|
1302
|
+
key: 'el',
|
1303
|
+
get: function get() {
|
1304
|
+
return this._el;
|
1305
|
+
}
|
1306
|
+
}, {
|
1307
|
+
key: 'detectChange',
|
1308
|
+
get: function get() {
|
1309
|
+
return this._detectChange;
|
1310
|
+
},
|
1311
|
+
set: function set(val) {
|
1312
|
+
this._detectChange = val;
|
1313
|
+
}
|
1314
|
+
}, {
|
1315
|
+
key: 'detectBlur',
|
1316
|
+
get: function get() {
|
1317
|
+
return this._detectBlur;
|
1318
|
+
},
|
1319
|
+
set: function set(val) {
|
1320
|
+
this._detectBlur = val;
|
1321
|
+
}
|
1322
|
+
}]);
|
1323
|
+
return BaseValidation;
|
1324
|
+
}();
|
1325
|
+
|
1326
|
+
/**
|
1327
|
+
* CheckboxValidation class
|
1328
|
+
*/
|
1329
|
+
|
1330
|
+
var CheckboxValidation = function (_BaseValidation) {
|
1331
|
+
babelHelpers.inherits(CheckboxValidation, _BaseValidation);
|
1332
|
+
|
1333
|
+
function CheckboxValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) {
|
1334
|
+
babelHelpers.classCallCheck(this, CheckboxValidation);
|
1335
|
+
|
1336
|
+
var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange));
|
1337
|
+
|
1338
|
+
_this._inits = [];
|
1339
|
+
return _this;
|
1340
|
+
}
|
1341
|
+
|
1342
|
+
CheckboxValidation.prototype.manageElement = function manageElement(el, initial) {
|
1343
|
+
var _this2 = this;
|
1344
|
+
|
1345
|
+
var scope = this._getScope();
|
1346
|
+
var item = this._addItem(el, initial);
|
1347
|
+
|
1348
|
+
var model = item.model = this._model;
|
1349
|
+
if (model) {
|
1350
|
+
var value = this._evalModel(model, this._filters);
|
1351
|
+
if (Array.isArray(value)) {
|
1352
|
+
this._setChecked(value, item.el);
|
1353
|
+
item.unwatch = scope.$watch(model, function (val, old) {
|
1354
|
+
if (val !== old) {
|
1355
|
+
if (_this2.guardValidate(item.el, 'change')) {
|
1356
|
+
return;
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
_this2.handleValidate(item.el, { noopable: item.initial });
|
1360
|
+
if (item.initial) {
|
1361
|
+
item.initial = null;
|
1362
|
+
}
|
1363
|
+
}
|
1364
|
+
});
|
1365
|
+
} else {
|
1366
|
+
el.checked = value || false;
|
1367
|
+
this._init = el.checked;
|
1368
|
+
item.init = el.checked;
|
1369
|
+
item.value = el.value;
|
1370
|
+
item.unwatch = scope.$watch(model, function (val, old) {
|
1371
|
+
if (val !== old) {
|
1372
|
+
if (_this2.guardValidate(el, 'change')) {
|
1373
|
+
return;
|
1374
|
+
}
|
1375
|
+
|
1376
|
+
_this2.handleValidate(el, { noopable: item.initial });
|
1377
|
+
if (item.initial) {
|
1378
|
+
item.initial = null;
|
1379
|
+
}
|
1380
|
+
}
|
1381
|
+
});
|
1382
|
+
}
|
1383
|
+
} else {
|
1384
|
+
var options = { field: this.field, noopable: initial };
|
1385
|
+
if (this._checkClassIds(el)) {
|
1386
|
+
options.el = el;
|
1387
|
+
}
|
1388
|
+
this._validator.validate(options);
|
1389
|
+
}
|
1390
|
+
};
|
1391
|
+
|
1392
|
+
CheckboxValidation.prototype.unmanageElement = function unmanageElement(el) {
|
1393
|
+
var found = -1;
|
1394
|
+
each(this._inits, function (item, index) {
|
1395
|
+
if (item.el === el) {
|
1396
|
+
found = index;
|
1397
|
+
if (item.unwatch && item.model) {
|
1398
|
+
item.unwatch();
|
1399
|
+
item.unwatch = null;
|
1400
|
+
item.model = null;
|
1401
|
+
}
|
1402
|
+
}
|
1403
|
+
});
|
1404
|
+
if (found === -1) {
|
1405
|
+
return;
|
1406
|
+
}
|
1407
|
+
|
1408
|
+
this._inits.splice(found, 1);
|
1409
|
+
this._validator.validate({ field: this.field });
|
1410
|
+
};
|
1411
|
+
|
1412
|
+
CheckboxValidation.prototype.willUpdateFlags = function willUpdateFlags() {
|
1413
|
+
var _this3 = this;
|
1414
|
+
|
1415
|
+
var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
|
1416
|
+
|
1417
|
+
each(this._inits, function (item, index) {
|
1418
|
+
touched && _this3.willUpdateTouched(item.el, 'blur');
|
1419
|
+
_this3.willUpdateDirty(item.el);
|
1420
|
+
_this3.willUpdateModified(item.el);
|
1421
|
+
});
|
1422
|
+
};
|
1423
|
+
|
1424
|
+
CheckboxValidation.prototype.reset = function reset() {
|
1425
|
+
this.resetValidationNoopable();
|
1426
|
+
this.resetFlags();
|
1427
|
+
each(this._inits, function (item, index) {
|
1428
|
+
item.init = item.el.checked;
|
1429
|
+
item.value = item.el.value;
|
1430
|
+
});
|
1431
|
+
};
|
1432
|
+
|
1433
|
+
CheckboxValidation.prototype.updateClasses = function updateClasses(results) {
|
1434
|
+
var _this4 = this;
|
1435
|
+
|
1436
|
+
var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
|
1437
|
+
|
1438
|
+
if (el) {
|
1439
|
+
// for another element
|
1440
|
+
this._updateClasses(el, results);
|
1441
|
+
} else {
|
1442
|
+
each(this._inits, function (item, index) {
|
1443
|
+
_this4._updateClasses(item.el, results);
|
1444
|
+
});
|
1445
|
+
}
|
1446
|
+
};
|
1447
|
+
|
1448
|
+
CheckboxValidation.prototype._addItem = function _addItem(el, initial) {
|
1449
|
+
var item = {
|
1450
|
+
el: el,
|
1451
|
+
init: el.checked,
|
1452
|
+
value: el.value,
|
1453
|
+
initial: initial
|
1454
|
+
};
|
1455
|
+
|
1456
|
+
var classIds = el.getAttribute(VALIDATE_UPDATE);
|
1457
|
+
if (classIds) {
|
1458
|
+
el.removeAttribute(VALIDATE_UPDATE);
|
1459
|
+
item.classIds = classIds.split(',');
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
this._inits.push(item);
|
1463
|
+
return item;
|
1464
|
+
};
|
1465
|
+
|
1466
|
+
CheckboxValidation.prototype._setChecked = function _setChecked(values, el) {
|
1467
|
+
for (var i = 0, l = values.length; i < l; i++) {
|
1468
|
+
var value = values[i];
|
1469
|
+
if (!el.disabled && el.value === value && !el.checked) {
|
1470
|
+
el.checked = true;
|
1471
|
+
}
|
1472
|
+
}
|
1473
|
+
};
|
1474
|
+
|
1475
|
+
CheckboxValidation.prototype._getValue = function _getValue(el) {
|
1476
|
+
var _this5 = this;
|
1477
|
+
|
1478
|
+
if (!this._inits || this._inits.length === 0) {
|
1479
|
+
return el.checked;
|
1480
|
+
} else {
|
1481
|
+
var _ret = function () {
|
1482
|
+
var vals = [];
|
1483
|
+
each(_this5._inits, function (item, index) {
|
1484
|
+
item.el.checked && vals.push(item.el.value);
|
1485
|
+
});
|
1486
|
+
return {
|
1487
|
+
v: vals
|
1488
|
+
};
|
1489
|
+
}();
|
1490
|
+
|
1491
|
+
if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v;
|
1492
|
+
}
|
1493
|
+
};
|
1494
|
+
|
1495
|
+
CheckboxValidation.prototype._getClassIds = function _getClassIds(el) {
|
1496
|
+
var classIds = void 0;
|
1497
|
+
each(this._inits, function (item, index) {
|
1498
|
+
if (item.el === el) {
|
1499
|
+
classIds = item.classIds;
|
1500
|
+
}
|
1501
|
+
});
|
1502
|
+
return classIds;
|
1503
|
+
};
|
1504
|
+
|
1505
|
+
CheckboxValidation.prototype._checkModified = function _checkModified(target) {
|
1506
|
+
var _this6 = this;
|
1507
|
+
|
1508
|
+
if (this._inits.length === 0) {
|
1509
|
+
return this._init !== target.checked;
|
1510
|
+
} else {
|
1511
|
+
var _ret2 = function () {
|
1512
|
+
var modified = false;
|
1513
|
+
each(_this6._inits, function (item, index) {
|
1514
|
+
if (!modified) {
|
1515
|
+
modified = item.init !== item.el.checked;
|
1516
|
+
}
|
1517
|
+
});
|
1518
|
+
return {
|
1519
|
+
v: modified
|
1520
|
+
};
|
1521
|
+
}();
|
1522
|
+
|
1523
|
+
if ((typeof _ret2 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret2)) === "object") return _ret2.v;
|
1524
|
+
}
|
1525
|
+
};
|
1526
|
+
|
1527
|
+
return CheckboxValidation;
|
1528
|
+
}(BaseValidation);
|
1529
|
+
|
1530
|
+
/**
|
1531
|
+
* RadioValidation class
|
1532
|
+
*/
|
1533
|
+
|
1534
|
+
var RadioValidation = function (_BaseValidation) {
|
1535
|
+
babelHelpers.inherits(RadioValidation, _BaseValidation);
|
1536
|
+
|
1537
|
+
function RadioValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) {
|
1538
|
+
babelHelpers.classCallCheck(this, RadioValidation);
|
1539
|
+
|
1540
|
+
var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange));
|
1541
|
+
|
1542
|
+
_this._inits = [];
|
1543
|
+
return _this;
|
1544
|
+
}
|
1545
|
+
|
1546
|
+
RadioValidation.prototype.manageElement = function manageElement(el, initial) {
|
1547
|
+
var _this2 = this;
|
1548
|
+
|
1549
|
+
var scope = this._getScope();
|
1550
|
+
var item = this._addItem(el, initial);
|
1551
|
+
|
1552
|
+
var model = item.model = this._model;
|
1553
|
+
if (model) {
|
1554
|
+
var value = this._evalModel(model, this._filters);
|
1555
|
+
this._setChecked(value, el, item);
|
1556
|
+
item.unwatch = scope.$watch(model, function (val, old) {
|
1557
|
+
if (val !== old) {
|
1558
|
+
if (_this2.guardValidate(item.el, 'change')) {
|
1559
|
+
return;
|
1560
|
+
}
|
1561
|
+
|
1562
|
+
_this2.handleValidate(el, { noopable: item.initial });
|
1563
|
+
if (item.initial) {
|
1564
|
+
item.initial = null;
|
1565
|
+
}
|
1566
|
+
}
|
1567
|
+
});
|
1568
|
+
} else {
|
1569
|
+
var options = { field: this.field, noopable: initial };
|
1570
|
+
if (this._checkClassIds(el)) {
|
1571
|
+
options.el = el;
|
1572
|
+
}
|
1573
|
+
this._validator.validate(options);
|
1574
|
+
}
|
1575
|
+
};
|
1576
|
+
|
1577
|
+
RadioValidation.prototype.unmanageElement = function unmanageElement(el) {
|
1578
|
+
var found = -1;
|
1579
|
+
each(this._inits, function (item, index) {
|
1580
|
+
if (item.el === el) {
|
1581
|
+
found = index;
|
1582
|
+
}
|
1583
|
+
});
|
1584
|
+
if (found === -1) {
|
1585
|
+
return;
|
1586
|
+
}
|
1587
|
+
|
1588
|
+
this._inits.splice(found, 1);
|
1589
|
+
this._validator.validate({ field: this.field });
|
1590
|
+
};
|
1591
|
+
|
1592
|
+
RadioValidation.prototype.willUpdateFlags = function willUpdateFlags() {
|
1593
|
+
var _this3 = this;
|
1594
|
+
|
1595
|
+
var touched = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
|
1596
|
+
|
1597
|
+
each(this._inits, function (item, index) {
|
1598
|
+
touched && _this3.willUpdateTouched(item.el, 'blur');
|
1599
|
+
_this3.willUpdateDirty(item.el);
|
1600
|
+
_this3.willUpdateModified(item.el);
|
1601
|
+
});
|
1602
|
+
};
|
1603
|
+
|
1604
|
+
RadioValidation.prototype.reset = function reset() {
|
1605
|
+
this.resetValidationNoopable();
|
1606
|
+
this.resetFlags();
|
1607
|
+
each(this._inits, function (item, index) {
|
1608
|
+
item.init = item.el.checked;
|
1609
|
+
item.value = item.el.value;
|
1610
|
+
});
|
1611
|
+
};
|
1612
|
+
|
1613
|
+
RadioValidation.prototype.updateClasses = function updateClasses(results) {
|
1614
|
+
var _this4 = this;
|
1615
|
+
|
1616
|
+
var el = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
|
1617
|
+
|
1618
|
+
if (el) {
|
1619
|
+
// for another element
|
1620
|
+
this._updateClasses(el, results);
|
1621
|
+
} else {
|
1622
|
+
each(this._inits, function (item, index) {
|
1623
|
+
_this4._updateClasses(item.el, results);
|
1624
|
+
});
|
1625
|
+
}
|
1626
|
+
};
|
1627
|
+
|
1628
|
+
RadioValidation.prototype._addItem = function _addItem(el, initial) {
|
1629
|
+
var item = {
|
1630
|
+
el: el,
|
1631
|
+
init: el.checked,
|
1632
|
+
value: el.value,
|
1633
|
+
initial: initial
|
1634
|
+
};
|
1635
|
+
|
1636
|
+
var classIds = el.getAttribute(VALIDATE_UPDATE);
|
1637
|
+
if (classIds) {
|
1638
|
+
el.removeAttribute(VALIDATE_UPDATE);
|
1639
|
+
item.classIds = classIds.split(',');
|
1640
|
+
}
|
1641
|
+
|
1642
|
+
this._inits.push(item);
|
1643
|
+
return item;
|
1644
|
+
};
|
1645
|
+
|
1646
|
+
RadioValidation.prototype._setChecked = function _setChecked(value, el, item) {
|
1647
|
+
if (el.value === value) {
|
1648
|
+
el.checked = true;
|
1649
|
+
this._init = el.checked;
|
1650
|
+
item.init = el.checked;
|
1651
|
+
item.value = value;
|
1652
|
+
}
|
1653
|
+
};
|
1654
|
+
|
1655
|
+
RadioValidation.prototype._getValue = function _getValue(el) {
|
1656
|
+
var _this5 = this;
|
1657
|
+
|
1658
|
+
if (!this._inits || this._inits.length === 0) {
|
1659
|
+
return el.checked;
|
1660
|
+
} else {
|
1661
|
+
var _ret = function () {
|
1662
|
+
var vals = [];
|
1663
|
+
each(_this5._inits, function (item, index) {
|
1664
|
+
item.el.checked && vals.push(item.el.value);
|
1665
|
+
});
|
1666
|
+
return {
|
1667
|
+
v: vals
|
1668
|
+
};
|
1669
|
+
}();
|
1670
|
+
|
1671
|
+
if ((typeof _ret === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret)) === "object") return _ret.v;
|
1672
|
+
}
|
1673
|
+
};
|
1674
|
+
|
1675
|
+
RadioValidation.prototype._getClassIds = function _getClassIds(el) {
|
1676
|
+
var classIds = void 0;
|
1677
|
+
each(this._inits, function (item, index) {
|
1678
|
+
if (item.el === el) {
|
1679
|
+
classIds = item.classIds;
|
1680
|
+
}
|
1681
|
+
});
|
1682
|
+
return classIds;
|
1683
|
+
};
|
1684
|
+
|
1685
|
+
RadioValidation.prototype._checkModified = function _checkModified(target) {
|
1686
|
+
var _this6 = this;
|
1687
|
+
|
1688
|
+
if (this._inits.length === 0) {
|
1689
|
+
return this._init !== target.checked;
|
1690
|
+
} else {
|
1691
|
+
var _ret2 = function () {
|
1692
|
+
var modified = false;
|
1693
|
+
each(_this6._inits, function (item, index) {
|
1694
|
+
if (!modified) {
|
1695
|
+
modified = item.init !== item.el.checked;
|
1696
|
+
}
|
1697
|
+
});
|
1698
|
+
return {
|
1699
|
+
v: modified
|
1700
|
+
};
|
1701
|
+
}();
|
1702
|
+
|
1703
|
+
if ((typeof _ret2 === 'undefined' ? 'undefined' : babelHelpers.typeof(_ret2)) === "object") return _ret2.v;
|
1704
|
+
}
|
1705
|
+
};
|
1706
|
+
|
1707
|
+
return RadioValidation;
|
1708
|
+
}(BaseValidation);
|
1709
|
+
|
1710
|
+
/**
|
1711
|
+
* SelectValidation class
|
1712
|
+
*/
|
1713
|
+
|
1714
|
+
var SelectValidation = function (_BaseValidation) {
|
1715
|
+
babelHelpers.inherits(SelectValidation, _BaseValidation);
|
1716
|
+
|
1717
|
+
function SelectValidation(field, model, vm, el, scope, validator, filters, detectBlur, detectChange) {
|
1718
|
+
babelHelpers.classCallCheck(this, SelectValidation);
|
1719
|
+
|
1720
|
+
var _this = babelHelpers.possibleConstructorReturn(this, _BaseValidation.call(this, field, model, vm, el, scope, validator, filters, detectBlur, detectChange));
|
1721
|
+
|
1722
|
+
_this._multiple = _this._el.hasAttribute('multiple');
|
1723
|
+
return _this;
|
1724
|
+
}
|
1725
|
+
|
1726
|
+
SelectValidation.prototype.manageElement = function manageElement(el, initial) {
|
1727
|
+
var _this2 = this;
|
1728
|
+
|
1729
|
+
var scope = this._getScope();
|
1730
|
+
var model = this._model;
|
1731
|
+
|
1732
|
+
this._initial = initial;
|
1733
|
+
|
1734
|
+
var classIds = el.getAttribute(VALIDATE_UPDATE);
|
1735
|
+
if (classIds) {
|
1736
|
+
el.removeAttribute(VALIDATE_UPDATE);
|
1737
|
+
this._classIds = classIds.split(',');
|
1738
|
+
}
|
1739
|
+
|
1740
|
+
if (model) {
|
1741
|
+
var value = this._evalModel(model, this._filters);
|
1742
|
+
var values = !Array.isArray(value) ? [value] : value;
|
1743
|
+
this._setOption(values, el);
|
1744
|
+
this._unwatch = scope.$watch(model, function (val, old) {
|
1745
|
+
var values1 = !Array.isArray(val) ? [val] : val;
|
1746
|
+
var values2 = !Array.isArray(old) ? [old] : old;
|
1747
|
+
if (values1.slice().sort().toString() !== values2.slice().sort().toString()) {
|
1748
|
+
if (_this2.guardValidate(el, 'change')) {
|
1749
|
+
return;
|
1750
|
+
}
|
1751
|
+
|
1752
|
+
_this2.handleValidate(el, { noopable: _this2._initial });
|
1753
|
+
if (_this2._initial) {
|
1754
|
+
_this2._initial = null;
|
1755
|
+
}
|
1756
|
+
}
|
1757
|
+
});
|
1758
|
+
}
|
1759
|
+
};
|
1760
|
+
|
1761
|
+
SelectValidation.prototype.unmanageElement = function unmanageElement(el) {
|
1762
|
+
this._unwatch && this._unwatch();
|
1763
|
+
};
|
1764
|
+
|
1765
|
+
SelectValidation.prototype._getValue = function _getValue(el) {
|
1766
|
+
var ret = [];
|
1767
|
+
|
1768
|
+
for (var i = 0, l = el.options.length; i < l; i++) {
|
1769
|
+
var option = el.options[i];
|
1770
|
+
if (!option.disabled && option.selected) {
|
1771
|
+
ret.push(option.value);
|
1772
|
+
}
|
1773
|
+
}
|
1774
|
+
|
1775
|
+
return ret;
|
1776
|
+
};
|
1777
|
+
|
1778
|
+
SelectValidation.prototype._setOption = function _setOption(values, el) {
|
1779
|
+
for (var i = 0, l = values.length; i < l; i++) {
|
1780
|
+
var value = values[i];
|
1781
|
+
for (var j = 0, m = el.options.length; j < m; j++) {
|
1782
|
+
var option = el.options[j];
|
1783
|
+
if (!option.disabled && option.value === value && (!option.hasAttribute('selected') || !option.selected)) {
|
1784
|
+
option.selected = true;
|
1785
|
+
}
|
1786
|
+
}
|
1787
|
+
}
|
1788
|
+
};
|
1789
|
+
|
1790
|
+
SelectValidation.prototype._checkModified = function _checkModified(target) {
|
1791
|
+
var values = this._getValue(target).slice().sort();
|
1792
|
+
if (this._init.length !== values.length) {
|
1793
|
+
return true;
|
1794
|
+
} else {
|
1795
|
+
var inits = this._init.slice().sort();
|
1796
|
+
return inits.toString() !== values.toString();
|
1797
|
+
}
|
1798
|
+
};
|
1799
|
+
|
1800
|
+
return SelectValidation;
|
1801
|
+
}(BaseValidation);
|
1802
|
+
|
1803
|
+
/**
|
1804
|
+
* Validator class
|
1805
|
+
*/
|
1806
|
+
|
1807
|
+
var Validator$1 = function () {
|
1808
|
+
function Validator(name, dir, groups, classes) {
|
1809
|
+
var _this = this;
|
1810
|
+
|
1811
|
+
babelHelpers.classCallCheck(this, Validator);
|
1812
|
+
|
1813
|
+
this.name = name;
|
1814
|
+
|
1815
|
+
this._scope = {};
|
1816
|
+
this._dir = dir;
|
1817
|
+
this._validations = {};
|
1818
|
+
this._checkboxValidations = {};
|
1819
|
+
this._radioValidations = {};
|
1820
|
+
this._groups = groups;
|
1821
|
+
this._groupValidations = {};
|
1822
|
+
this._events = {};
|
1823
|
+
this._modified = false;
|
1824
|
+
this._classes = classes;
|
1825
|
+
|
1826
|
+
each(groups, function (group) {
|
1827
|
+
_this._groupValidations[group] = [];
|
1828
|
+
});
|
1829
|
+
}
|
1830
|
+
|
1831
|
+
Validator.prototype.enableReactive = function enableReactive() {
|
1832
|
+
var vm = this._dir.vm;
|
1833
|
+
|
1834
|
+
// define the validation scope
|
1835
|
+
exports$1.Vue.util.defineReactive(vm, this.name, this._scope);
|
1836
|
+
vm._validatorMaps[this.name] = this;
|
1837
|
+
|
1838
|
+
// define the validation resetting meta method to vue instance
|
1839
|
+
this._defineResetValidation();
|
1840
|
+
|
1841
|
+
// define the validate manually meta method to vue instance
|
1842
|
+
this._defineValidate();
|
1843
|
+
|
1844
|
+
// define manually the validation errors
|
1845
|
+
this._defineSetValidationErrors();
|
1846
|
+
};
|
1847
|
+
|
1848
|
+
Validator.prototype.disableReactive = function disableReactive() {
|
1849
|
+
var vm = this._dir.vm;
|
1850
|
+
vm.$setValidationErrors = null;
|
1851
|
+
delete vm['$setValidationErrors'];
|
1852
|
+
vm.$validate = null;
|
1853
|
+
delete vm['$validate'];
|
1854
|
+
vm.$resetValidation = null;
|
1855
|
+
delete vm['$resetValidation'];
|
1856
|
+
vm._validatorMaps[this.name] = null;
|
1857
|
+
delete vm._validatorMaps[this.name];
|
1858
|
+
vm[this.name] = null;
|
1859
|
+
delete vm[this.name];
|
1860
|
+
};
|
1861
|
+
|
1862
|
+
Validator.prototype.registerEvents = function registerEvents() {
|
1863
|
+
var isSimplePath = exports$1.Vue.parsers.expression.isSimplePath;
|
1864
|
+
|
1865
|
+
var attrs = this._dir.el.attributes;
|
1866
|
+
for (var i = 0, l = attrs.length; i < l; i++) {
|
1867
|
+
var event = attrs[i].name;
|
1868
|
+
if (REGEX_EVENT.test(event)) {
|
1869
|
+
var value = attrs[i].value;
|
1870
|
+
if (isSimplePath(value)) {
|
1871
|
+
value += '.apply(this, $arguments)';
|
1872
|
+
}
|
1873
|
+
event = event.replace(REGEX_EVENT, '');
|
1874
|
+
this._events[this._getEventName(event)] = this._dir.vm.$eval(value, true);
|
1875
|
+
}
|
1876
|
+
}
|
1877
|
+
};
|
1878
|
+
|
1879
|
+
Validator.prototype.unregisterEvents = function unregisterEvents() {
|
1880
|
+
var _this2 = this;
|
1881
|
+
|
1882
|
+
each(this._events, function (handler, event) {
|
1883
|
+
_this2._events[event] = null;
|
1884
|
+
delete _this2._events[event];
|
1885
|
+
});
|
1886
|
+
};
|
1887
|
+
|
1888
|
+
Validator.prototype.manageValidation = function manageValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) {
|
1889
|
+
var validation = null;
|
1890
|
+
|
1891
|
+
if (el.tagName === 'SELECT') {
|
1892
|
+
validation = this._manageSelectValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange);
|
1893
|
+
} else if (el.type === 'checkbox') {
|
1894
|
+
validation = this._manageCheckboxValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange);
|
1895
|
+
} else if (el.type === 'radio') {
|
1896
|
+
validation = this._manageRadioValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange);
|
1897
|
+
} else {
|
1898
|
+
validation = this._manageBaseValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange);
|
1899
|
+
}
|
1900
|
+
|
1901
|
+
validation.setValidationClasses(this._classes);
|
1902
|
+
|
1903
|
+
return validation;
|
1904
|
+
};
|
1905
|
+
|
1906
|
+
Validator.prototype.unmanageValidation = function unmanageValidation(field, el) {
|
1907
|
+
if (el.type === 'checkbox') {
|
1908
|
+
this._unmanageCheckboxValidation(field, el);
|
1909
|
+
} else if (el.type === 'radio') {
|
1910
|
+
this._unmanageRadioValidation(field, el);
|
1911
|
+
} else if (el.tagName === 'SELECT') {
|
1912
|
+
this._unmanageSelectValidation(field, el);
|
1913
|
+
} else {
|
1914
|
+
this._unmanageBaseValidation(field, el);
|
1915
|
+
}
|
1916
|
+
};
|
1917
|
+
|
1918
|
+
Validator.prototype.addGroupValidation = function addGroupValidation(group, field) {
|
1919
|
+
var indexOf = exports$1.Vue.util.indexOf;
|
1920
|
+
|
1921
|
+
var validation = this._getValidationFrom(field);
|
1922
|
+
var validations = this._groupValidations[group];
|
1923
|
+
|
1924
|
+
validations && !~indexOf(validations, validation) && validations.push(validation);
|
1925
|
+
};
|
1926
|
+
|
1927
|
+
Validator.prototype.removeGroupValidation = function removeGroupValidation(group, field) {
|
1928
|
+
var validation = this._getValidationFrom(field);
|
1929
|
+
var validations = this._groupValidations[group];
|
1930
|
+
|
1931
|
+
validations && pull(validations, validation);
|
1932
|
+
};
|
1933
|
+
|
1934
|
+
Validator.prototype.validate = function validate() {
|
1935
|
+
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
1936
|
+
|
1937
|
+
var _ref$el = _ref.el;
|
1938
|
+
var el = _ref$el === undefined ? null : _ref$el;
|
1939
|
+
var _ref$field = _ref.field;
|
1940
|
+
var field = _ref$field === undefined ? null : _ref$field;
|
1941
|
+
var _ref$touched = _ref.touched;
|
1942
|
+
var touched = _ref$touched === undefined ? false : _ref$touched;
|
1943
|
+
var _ref$noopable = _ref.noopable;
|
1944
|
+
var noopable = _ref$noopable === undefined ? false : _ref$noopable;
|
1945
|
+
var _ref$cb = _ref.cb;
|
1946
|
+
var cb = _ref$cb === undefined ? null : _ref$cb;
|
1947
|
+
|
1948
|
+
if (!field) {
|
1949
|
+
// all
|
1950
|
+
each(this.validations, function (validation, key) {
|
1951
|
+
validation.willUpdateFlags(touched);
|
1952
|
+
});
|
1953
|
+
this._validates(cb);
|
1954
|
+
} else {
|
1955
|
+
// each field
|
1956
|
+
this._validate(field, touched, noopable, el, cb);
|
1957
|
+
}
|
1958
|
+
};
|
1959
|
+
|
1960
|
+
Validator.prototype.setupScope = function setupScope() {
|
1961
|
+
var _this3 = this;
|
1962
|
+
|
1963
|
+
this._defineProperties(function () {
|
1964
|
+
return _this3.validations;
|
1965
|
+
}, function () {
|
1966
|
+
return _this3._scope;
|
1967
|
+
});
|
1968
|
+
|
1969
|
+
each(this._groups, function (name) {
|
1970
|
+
var validations = _this3._groupValidations[name];
|
1971
|
+
var group = {};
|
1972
|
+
exports$1.Vue.set(_this3._scope, name, group);
|
1973
|
+
_this3._defineProperties(function () {
|
1974
|
+
return validations;
|
1975
|
+
}, function () {
|
1976
|
+
return group;
|
1977
|
+
});
|
1978
|
+
});
|
1979
|
+
};
|
1980
|
+
|
1981
|
+
Validator.prototype.waitFor = function waitFor(cb) {
|
1982
|
+
var method = '$activateValidator';
|
1983
|
+
var vm = this._dir.vm;
|
1984
|
+
|
1985
|
+
vm[method] = function () {
|
1986
|
+
cb();
|
1987
|
+
vm[method] = null;
|
1988
|
+
};
|
1989
|
+
};
|
1990
|
+
|
1991
|
+
Validator.prototype._defineResetValidation = function _defineResetValidation() {
|
1992
|
+
var _this4 = this;
|
1993
|
+
|
1994
|
+
this._dir.vm.$resetValidation = function (cb) {
|
1995
|
+
_this4._resetValidation(cb);
|
1996
|
+
};
|
1997
|
+
};
|
1998
|
+
|
1999
|
+
Validator.prototype._defineValidate = function _defineValidate() {
|
2000
|
+
var _this5 = this;
|
2001
|
+
|
2002
|
+
this._dir.vm.$validate = function () {
|
2003
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
2004
|
+
args[_key] = arguments[_key];
|
2005
|
+
}
|
2006
|
+
|
2007
|
+
var field = null;
|
2008
|
+
var touched = false;
|
2009
|
+
var cb = null;
|
2010
|
+
|
2011
|
+
each(args, function (arg, index) {
|
2012
|
+
if (typeof arg === 'string') {
|
2013
|
+
field = arg;
|
2014
|
+
} else if (typeof arg === 'boolean') {
|
2015
|
+
touched = arg;
|
2016
|
+
} else if (typeof arg === 'function') {
|
2017
|
+
cb = arg;
|
2018
|
+
}
|
2019
|
+
});
|
2020
|
+
|
2021
|
+
_this5.validate({ field: field, touched: touched, cb: cb });
|
2022
|
+
};
|
2023
|
+
};
|
2024
|
+
|
2025
|
+
Validator.prototype._defineSetValidationErrors = function _defineSetValidationErrors() {
|
2026
|
+
var _this6 = this;
|
2027
|
+
|
2028
|
+
this._dir.vm.$setValidationErrors = function (errors) {
|
2029
|
+
_this6._setValidationErrors(errors);
|
2030
|
+
};
|
2031
|
+
};
|
2032
|
+
|
2033
|
+
Validator.prototype._validate = function _validate(field) {
|
2034
|
+
var touched = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
|
2035
|
+
var noopable = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
|
2036
|
+
|
2037
|
+
var _this7 = this;
|
2038
|
+
|
2039
|
+
var el = arguments.length <= 3 || arguments[3] === undefined ? null : arguments[3];
|
2040
|
+
var cb = arguments.length <= 4 || arguments[4] === undefined ? null : arguments[4];
|
2041
|
+
|
2042
|
+
var scope = this._scope;
|
2043
|
+
|
2044
|
+
var validation = this._getValidationFrom(field);
|
2045
|
+
if (validation) {
|
2046
|
+
validation.willUpdateFlags(touched);
|
2047
|
+
validation.validate(function (results) {
|
2048
|
+
exports$1.Vue.set(scope, field, results);
|
2049
|
+
_this7._fireEvents();
|
2050
|
+
cb && cb();
|
2051
|
+
}, noopable, el);
|
2052
|
+
}
|
2053
|
+
};
|
2054
|
+
|
2055
|
+
Validator.prototype._validates = function _validates(cb) {
|
2056
|
+
var _this8 = this;
|
2057
|
+
|
2058
|
+
var scope = this._scope;
|
2059
|
+
|
2060
|
+
this._runValidates(function (validation, key, done) {
|
2061
|
+
validation.validate(function (results) {
|
2062
|
+
exports$1.Vue.set(scope, key, results);
|
2063
|
+
done();
|
2064
|
+
});
|
2065
|
+
}, function () {
|
2066
|
+
// finished
|
2067
|
+
_this8._fireEvents();
|
2068
|
+
cb && cb();
|
2069
|
+
});
|
2070
|
+
};
|
2071
|
+
|
2072
|
+
Validator.prototype._getValidationFrom = function _getValidationFrom(field) {
|
2073
|
+
return this._validations[field] || this._checkboxValidations[field] && this._checkboxValidations[field].validation || this._radioValidations[field] && this._radioValidations[field].validation;
|
2074
|
+
};
|
2075
|
+
|
2076
|
+
Validator.prototype._resetValidation = function _resetValidation(cb) {
|
2077
|
+
each(this.validations, function (validation, key) {
|
2078
|
+
validation.reset();
|
2079
|
+
});
|
2080
|
+
this._validates(cb);
|
2081
|
+
};
|
2082
|
+
|
2083
|
+
Validator.prototype._setValidationErrors = function _setValidationErrors(errors) {
|
2084
|
+
var _this9 = this;
|
2085
|
+
|
2086
|
+
var extend = exports$1.Vue.util.extend;
|
2087
|
+
|
2088
|
+
// make tempolaly errors
|
2089
|
+
|
2090
|
+
var temp = {};
|
2091
|
+
each(errors, function (error, index) {
|
2092
|
+
if (!temp[error.field]) {
|
2093
|
+
temp[error.field] = [];
|
2094
|
+
}
|
2095
|
+
temp[error.field].push(error);
|
2096
|
+
});
|
2097
|
+
|
2098
|
+
// set errors
|
2099
|
+
each(temp, function (values, field) {
|
2100
|
+
var results = _this9._scope[field];
|
2101
|
+
var newResults = {};
|
2102
|
+
|
2103
|
+
each(values, function (error) {
|
2104
|
+
if (error.validator) {
|
2105
|
+
results[error.validator] = error.message;
|
2106
|
+
}
|
2107
|
+
});
|
2108
|
+
|
2109
|
+
results.valid = false;
|
2110
|
+
results.invalid = true;
|
2111
|
+
results.errors = values;
|
2112
|
+
extend(newResults, results);
|
2113
|
+
|
2114
|
+
var validation = _this9._getValidationFrom(field);
|
2115
|
+
validation.willUpdateClasses(newResults, validation.el);
|
2116
|
+
|
2117
|
+
exports$1.Vue.set(_this9._scope, field, newResults);
|
2118
|
+
});
|
2119
|
+
};
|
2120
|
+
|
2121
|
+
Validator.prototype._manageBaseValidation = function _manageBaseValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) {
|
2122
|
+
var validation = this._validations[field] = new BaseValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange);
|
2123
|
+
validation.manageElement(el, initial);
|
2124
|
+
return validation;
|
2125
|
+
};
|
2126
|
+
|
2127
|
+
Validator.prototype._unmanageBaseValidation = function _unmanageBaseValidation(field, el) {
|
2128
|
+
var validation = this._validations[field];
|
2129
|
+
if (validation) {
|
2130
|
+
validation.unmanageElement(el);
|
2131
|
+
exports$1.Vue.delete(this._scope, field);
|
2132
|
+
this._validations[field] = null;
|
2133
|
+
delete this._validations[field];
|
2134
|
+
}
|
2135
|
+
};
|
2136
|
+
|
2137
|
+
Validator.prototype._manageCheckboxValidation = function _manageCheckboxValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) {
|
2138
|
+
var validationSet = this._checkboxValidations[field];
|
2139
|
+
if (!validationSet) {
|
2140
|
+
var validation = new CheckboxValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange);
|
2141
|
+
validationSet = { validation: validation, elements: 0 };
|
2142
|
+
this._checkboxValidations[field] = validationSet;
|
2143
|
+
}
|
2144
|
+
|
2145
|
+
validationSet.elements++;
|
2146
|
+
validationSet.validation.manageElement(el, initial);
|
2147
|
+
return validationSet.validation;
|
2148
|
+
};
|
2149
|
+
|
2150
|
+
Validator.prototype._unmanageCheckboxValidation = function _unmanageCheckboxValidation(field, el) {
|
2151
|
+
var validationSet = this._checkboxValidations[field];
|
2152
|
+
if (validationSet) {
|
2153
|
+
validationSet.elements--;
|
2154
|
+
validationSet.validation.unmanageElement(el);
|
2155
|
+
if (validationSet.elements === 0) {
|
2156
|
+
exports$1.Vue.delete(this._scope, field);
|
2157
|
+
this._checkboxValidations[field] = null;
|
2158
|
+
delete this._checkboxValidations[field];
|
2159
|
+
}
|
2160
|
+
}
|
2161
|
+
};
|
2162
|
+
|
2163
|
+
Validator.prototype._manageRadioValidation = function _manageRadioValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) {
|
2164
|
+
var validationSet = this._radioValidations[field];
|
2165
|
+
if (!validationSet) {
|
2166
|
+
var validation = new RadioValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange);
|
2167
|
+
validationSet = { validation: validation, elements: 0 };
|
2168
|
+
this._radioValidations[field] = validationSet;
|
2169
|
+
}
|
2170
|
+
|
2171
|
+
validationSet.elements++;
|
2172
|
+
validationSet.validation.manageElement(el, initial);
|
2173
|
+
return validationSet.validation;
|
2174
|
+
};
|
2175
|
+
|
2176
|
+
Validator.prototype._unmanageRadioValidation = function _unmanageRadioValidation(field, el) {
|
2177
|
+
var validationSet = this._radioValidations[field];
|
2178
|
+
if (validationSet) {
|
2179
|
+
validationSet.elements--;
|
2180
|
+
validationSet.validation.unmanageElement(el);
|
2181
|
+
if (validationSet.elements === 0) {
|
2182
|
+
exports$1.Vue.delete(this._scope, field);
|
2183
|
+
this._radioValidations[field] = null;
|
2184
|
+
delete this._radioValidations[field];
|
2185
|
+
}
|
2186
|
+
}
|
2187
|
+
};
|
2188
|
+
|
2189
|
+
Validator.prototype._manageSelectValidation = function _manageSelectValidation(field, model, vm, el, scope, filters, initial, detectBlur, detectChange) {
|
2190
|
+
var validation = this._validations[field] = new SelectValidation(field, model, vm, el, scope, this, filters, detectBlur, detectChange);
|
2191
|
+
validation.manageElement(el, initial);
|
2192
|
+
return validation;
|
2193
|
+
};
|
2194
|
+
|
2195
|
+
Validator.prototype._unmanageSelectValidation = function _unmanageSelectValidation(field, el) {
|
2196
|
+
var validation = this._validations[field];
|
2197
|
+
if (validation) {
|
2198
|
+
validation.unmanageElement(el);
|
2199
|
+
exports$1.Vue.delete(this._scope, field);
|
2200
|
+
this._validations[field] = null;
|
2201
|
+
delete this._validations[field];
|
2202
|
+
}
|
2203
|
+
};
|
2204
|
+
|
2205
|
+
Validator.prototype._fireEvent = function _fireEvent(type) {
|
2206
|
+
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
2207
|
+
args[_key2 - 1] = arguments[_key2];
|
2208
|
+
}
|
2209
|
+
|
2210
|
+
var handler = this._events[this._getEventName(type)];
|
2211
|
+
handler && this._dir.vm.$nextTick(function () {
|
2212
|
+
handler.apply(null, args);
|
2213
|
+
});
|
2214
|
+
};
|
2215
|
+
|
2216
|
+
Validator.prototype._fireEvents = function _fireEvents() {
|
2217
|
+
var scope = this._scope;
|
2218
|
+
|
2219
|
+
scope.touched && this._fireEvent('touched');
|
2220
|
+
scope.dirty && this._fireEvent('dirty');
|
2221
|
+
|
2222
|
+
if (this._modified !== scope.modified) {
|
2223
|
+
this._fireEvent('modified', scope.modified);
|
2224
|
+
this._modified = scope.modified;
|
2225
|
+
}
|
2226
|
+
|
2227
|
+
var valid = scope.valid;
|
2228
|
+
this._fireEvent(valid ? 'valid' : 'invalid');
|
2229
|
+
};
|
2230
|
+
|
2231
|
+
Validator.prototype._getEventName = function _getEventName(type) {
|
2232
|
+
return this.name + ':' + type;
|
2233
|
+
};
|
2234
|
+
|
2235
|
+
Validator.prototype._defineProperties = function _defineProperties(validationsGetter, targetGetter) {
|
2236
|
+
var _this10 = this;
|
2237
|
+
|
2238
|
+
var bind = exports$1.Vue.util.bind;
|
2239
|
+
|
2240
|
+
each({
|
2241
|
+
valid: { fn: this._defineValid, arg: validationsGetter },
|
2242
|
+
invalid: { fn: this._defineInvalid, arg: targetGetter },
|
2243
|
+
touched: { fn: this._defineTouched, arg: validationsGetter },
|
2244
|
+
untouched: { fn: this._defineUntouched, arg: targetGetter },
|
2245
|
+
modified: { fn: this._defineModified, arg: validationsGetter },
|
2246
|
+
dirty: { fn: this._defineDirty, arg: validationsGetter },
|
2247
|
+
pristine: { fn: this._definePristine, arg: targetGetter },
|
2248
|
+
errors: { fn: this._defineErrors, arg: validationsGetter }
|
2249
|
+
}, function (descriptor, name) {
|
2250
|
+
Object.defineProperty(targetGetter(), name, {
|
2251
|
+
enumerable: true,
|
2252
|
+
configurable: true,
|
2253
|
+
get: function get() {
|
2254
|
+
return bind(descriptor.fn, _this10)(descriptor.arg);
|
2255
|
+
}
|
2256
|
+
});
|
2257
|
+
});
|
2258
|
+
};
|
2259
|
+
|
2260
|
+
Validator.prototype._runValidates = function _runValidates(fn, cb) {
|
2261
|
+
var length = Object.keys(this.validations).length;
|
2262
|
+
|
2263
|
+
var count = 0;
|
2264
|
+
each(this.validations, function (validation, key) {
|
2265
|
+
fn(validation, key, function () {
|
2266
|
+
++count;
|
2267
|
+
count >= length && cb();
|
2268
|
+
});
|
2269
|
+
});
|
2270
|
+
};
|
2271
|
+
|
2272
|
+
Validator.prototype._walkValidations = function _walkValidations(validations, property, condition) {
|
2273
|
+
var _this11 = this;
|
2274
|
+
|
2275
|
+
var hasOwn = exports$1.Vue.util.hasOwn;
|
2276
|
+
var ret = condition;
|
2277
|
+
|
2278
|
+
each(validations, function (validation, key) {
|
2279
|
+
if (ret === !condition) {
|
2280
|
+
return;
|
2281
|
+
}
|
2282
|
+
if (hasOwn(_this11._scope, validation.field)) {
|
2283
|
+
var target = _this11._scope[validation.field];
|
2284
|
+
if (target && target[property] === !condition) {
|
2285
|
+
ret = !condition;
|
2286
|
+
}
|
2287
|
+
}
|
2288
|
+
});
|
2289
|
+
|
2290
|
+
return ret;
|
2291
|
+
};
|
2292
|
+
|
2293
|
+
Validator.prototype._defineValid = function _defineValid(validationsGetter) {
|
2294
|
+
return this._walkValidations(validationsGetter(), 'valid', true);
|
2295
|
+
};
|
2296
|
+
|
2297
|
+
Validator.prototype._defineInvalid = function _defineInvalid(scopeGetter) {
|
2298
|
+
return !scopeGetter().valid;
|
2299
|
+
};
|
2300
|
+
|
2301
|
+
Validator.prototype._defineTouched = function _defineTouched(validationsGetter) {
|
2302
|
+
return this._walkValidations(validationsGetter(), 'touched', false);
|
2303
|
+
};
|
2304
|
+
|
2305
|
+
Validator.prototype._defineUntouched = function _defineUntouched(scopeGetter) {
|
2306
|
+
return !scopeGetter().touched;
|
2307
|
+
};
|
2308
|
+
|
2309
|
+
Validator.prototype._defineModified = function _defineModified(validationsGetter) {
|
2310
|
+
return this._walkValidations(validationsGetter(), 'modified', false);
|
2311
|
+
};
|
2312
|
+
|
2313
|
+
Validator.prototype._defineDirty = function _defineDirty(validationsGetter) {
|
2314
|
+
return this._walkValidations(validationsGetter(), 'dirty', false);
|
2315
|
+
};
|
2316
|
+
|
2317
|
+
Validator.prototype._definePristine = function _definePristine(scopeGetter) {
|
2318
|
+
return !scopeGetter().dirty;
|
2319
|
+
};
|
2320
|
+
|
2321
|
+
Validator.prototype._defineErrors = function _defineErrors(validationsGetter) {
|
2322
|
+
var _this12 = this;
|
2323
|
+
|
2324
|
+
var hasOwn = exports$1.Vue.util.hasOwn;
|
2325
|
+
var isPlainObject = exports$1.Vue.util.isPlainObject;
|
2326
|
+
var errors = [];
|
2327
|
+
|
2328
|
+
each(validationsGetter(), function (validation, key) {
|
2329
|
+
if (hasOwn(_this12._scope, validation.field)) {
|
2330
|
+
var target = _this12._scope[validation.field];
|
2331
|
+
if (target && !empty(target.errors)) {
|
2332
|
+
each(target.errors, function (err, index) {
|
2333
|
+
var error = { field: validation.field };
|
2334
|
+
if (isPlainObject(err)) {
|
2335
|
+
if (err.validator) {
|
2336
|
+
error.validator = err.validator;
|
2337
|
+
}
|
2338
|
+
error.message = err.message;
|
2339
|
+
} else if (typeof err === 'string') {
|
2340
|
+
error.message = err;
|
2341
|
+
}
|
2342
|
+
errors.push(error);
|
2343
|
+
});
|
2344
|
+
}
|
2345
|
+
}
|
2346
|
+
});
|
2347
|
+
|
2348
|
+
return empty(errors) ? undefined : errors.sort(function (a, b) {
|
2349
|
+
return a.field < b.field ? -1 : 1;
|
2350
|
+
});
|
2351
|
+
};
|
2352
|
+
|
2353
|
+
babelHelpers.createClass(Validator, [{
|
2354
|
+
key: 'validations',
|
2355
|
+
get: function get() {
|
2356
|
+
var extend = exports$1.Vue.util.extend;
|
2357
|
+
|
2358
|
+
var ret = {};
|
2359
|
+
extend(ret, this._validations);
|
2360
|
+
|
2361
|
+
each(this._checkboxValidations, function (dataset, key) {
|
2362
|
+
ret[key] = dataset.validation;
|
2363
|
+
});
|
2364
|
+
|
2365
|
+
each(this._radioValidations, function (dataset, key) {
|
2366
|
+
ret[key] = dataset.validation;
|
2367
|
+
});
|
2368
|
+
|
2369
|
+
return ret;
|
2370
|
+
}
|
2371
|
+
}]);
|
2372
|
+
return Validator;
|
2373
|
+
}();
|
2374
|
+
|
2375
|
+
function Validator (Vue) {
|
2376
|
+
var FragmentFactory = Vue.FragmentFactory;
|
2377
|
+
var vIf = Vue.directive('if');
|
2378
|
+
var _Vue$util = Vue.util;
|
2379
|
+
var isArray = _Vue$util.isArray;
|
2380
|
+
var isPlainObject = _Vue$util.isPlainObject;
|
2381
|
+
var createAnchor = _Vue$util.createAnchor;
|
2382
|
+
var replace = _Vue$util.replace;
|
2383
|
+
var extend = _Vue$util.extend;
|
2384
|
+
var camelize = _Vue$util.camelize;
|
2385
|
+
|
2386
|
+
/**
|
2387
|
+
* `validator` element directive
|
2388
|
+
*/
|
2389
|
+
|
2390
|
+
Vue.elementDirective('validator', {
|
2391
|
+
params: ['name', 'groups', 'lazy', 'classes'],
|
2392
|
+
|
2393
|
+
bind: function bind() {
|
2394
|
+
var params = this.params;
|
2395
|
+
|
2396
|
+
if ('development' !== 'production' && !params.name) {
|
2397
|
+
warn('validator element requires a \'name\' attribute: ' + '(e.g. <validator name="validator1">...</validator>)');
|
2398
|
+
return;
|
2399
|
+
}
|
2400
|
+
|
2401
|
+
this.validatorName = '$' + camelize(params.name);
|
2402
|
+
if (!this.vm._validatorMaps) {
|
2403
|
+
throw new Error('Invalid validator management error');
|
2404
|
+
}
|
2405
|
+
|
2406
|
+
var classes = {};
|
2407
|
+
if (isPlainObject(this.params.classes)) {
|
2408
|
+
classes = this.params.classes;
|
2409
|
+
}
|
2410
|
+
|
2411
|
+
this.setupValidator(classes);
|
2412
|
+
this.setupFragment(params.lazy);
|
2413
|
+
},
|
2414
|
+
unbind: function unbind() {
|
2415
|
+
this.teardownFragment();
|
2416
|
+
this.teardownValidator();
|
2417
|
+
},
|
2418
|
+
getGroups: function getGroups() {
|
2419
|
+
var params = this.params;
|
2420
|
+
var groups = [];
|
2421
|
+
|
2422
|
+
if (params.groups) {
|
2423
|
+
if (isArray(params.groups)) {
|
2424
|
+
groups = params.groups;
|
2425
|
+
} else if (!isPlainObject(params.groups) && typeof params.groups === 'string') {
|
2426
|
+
groups.push(params.groups);
|
2427
|
+
}
|
2428
|
+
}
|
2429
|
+
|
2430
|
+
return groups;
|
2431
|
+
},
|
2432
|
+
setupValidator: function setupValidator(classes) {
|
2433
|
+
var validator = this.validator = new Validator$1(this.validatorName, this, this.getGroups(), classes);
|
2434
|
+
validator.enableReactive();
|
2435
|
+
validator.setupScope();
|
2436
|
+
validator.registerEvents();
|
2437
|
+
},
|
2438
|
+
teardownValidator: function teardownValidator() {
|
2439
|
+
this.validator.unregisterEvents();
|
2440
|
+
this.validator.disableReactive();
|
2441
|
+
|
2442
|
+
if (this.validatorName) {
|
2443
|
+
this.validatorName = null;
|
2444
|
+
this.validator = null;
|
2445
|
+
}
|
2446
|
+
},
|
2447
|
+
setupFragment: function setupFragment(lazy) {
|
2448
|
+
var _this = this;
|
2449
|
+
|
2450
|
+
var vm = this.vm;
|
2451
|
+
|
2452
|
+
this.validator.waitFor(function () {
|
2453
|
+
_this.anchor = createAnchor('vue-validator');
|
2454
|
+
replace(_this.el, _this.anchor);
|
2455
|
+
extend(vm.$options, { _validator: _this.validatorName });
|
2456
|
+
_this.factory = new FragmentFactory(vm, _this.el.innerHTML);
|
2457
|
+
vIf.insert.call(_this);
|
2458
|
+
});
|
2459
|
+
|
2460
|
+
!lazy && vm.$activateValidator();
|
2461
|
+
},
|
2462
|
+
teardownFragment: function teardownFragment() {
|
2463
|
+
vIf.unbind.call(this);
|
2464
|
+
}
|
2465
|
+
});
|
2466
|
+
}
|
2467
|
+
|
2468
|
+
function ValidatorError (Vue) {
|
2469
|
+
/**
|
2470
|
+
* ValidatorError component
|
2471
|
+
*/
|
2472
|
+
|
2473
|
+
var error = {
|
2474
|
+
name: 'validator-error',
|
2475
|
+
|
2476
|
+
props: {
|
2477
|
+
field: {
|
2478
|
+
type: String,
|
2479
|
+
required: true
|
2480
|
+
},
|
2481
|
+
validator: {
|
2482
|
+
type: String
|
2483
|
+
},
|
2484
|
+
message: {
|
2485
|
+
type: String,
|
2486
|
+
required: true
|
2487
|
+
},
|
2488
|
+
partial: {
|
2489
|
+
type: String,
|
2490
|
+
default: 'validator-error-default'
|
2491
|
+
}
|
2492
|
+
},
|
2493
|
+
|
2494
|
+
template: '<div><partial :name="partial"></partial></div>',
|
2495
|
+
|
2496
|
+
partials: {}
|
2497
|
+
};
|
2498
|
+
|
2499
|
+
// only use ValidatorError component
|
2500
|
+
error.partials['validator-error-default'] = '<p>{{field}}: {{message}}</p>';
|
2501
|
+
|
2502
|
+
return error;
|
2503
|
+
}
|
2504
|
+
|
2505
|
+
function Errors (Vue) {
|
2506
|
+
var _ = Vue.util;
|
2507
|
+
var error = ValidatorError(Vue); // import ValidatorError component
|
2508
|
+
|
2509
|
+
/**
|
2510
|
+
* ValidatorErrors component
|
2511
|
+
*/
|
2512
|
+
|
2513
|
+
var errors = {
|
2514
|
+
name: 'validator-errors',
|
2515
|
+
|
2516
|
+
props: {
|
2517
|
+
validation: {
|
2518
|
+
type: Object,
|
2519
|
+
required: true
|
2520
|
+
},
|
2521
|
+
group: {
|
2522
|
+
type: String,
|
2523
|
+
default: null
|
2524
|
+
},
|
2525
|
+
field: {
|
2526
|
+
type: String,
|
2527
|
+
default: null
|
2528
|
+
},
|
2529
|
+
component: {
|
2530
|
+
type: String,
|
2531
|
+
default: 'validator-error'
|
2532
|
+
}
|
2533
|
+
},
|
2534
|
+
|
2535
|
+
computed: {
|
2536
|
+
errors: function errors() {
|
2537
|
+
var _this = this;
|
2538
|
+
|
2539
|
+
if (this.group !== null) {
|
2540
|
+
return this.validation[this.group].errors;
|
2541
|
+
} else if (this.field !== null) {
|
2542
|
+
var target = this.validation[this.field];
|
2543
|
+
if (!target.errors) {
|
2544
|
+
return;
|
2545
|
+
}
|
2546
|
+
|
2547
|
+
return target.errors.map(function (error) {
|
2548
|
+
var err = { field: _this.field };
|
2549
|
+
if (_.isPlainObject(error)) {
|
2550
|
+
if (error.validator) {
|
2551
|
+
err.validator = error.validator;
|
2552
|
+
}
|
2553
|
+
err.message = error.message;
|
2554
|
+
} else if (typeof error === 'string') {
|
2555
|
+
err.message = error;
|
2556
|
+
}
|
2557
|
+
return err;
|
2558
|
+
});
|
2559
|
+
} else {
|
2560
|
+
return this.validation.errors;
|
2561
|
+
}
|
2562
|
+
}
|
2563
|
+
},
|
2564
|
+
|
2565
|
+
template: '<template v-for="error in errors">' + '<component :is="component" :partial="partial" :field="error.field" :validator="error.validator" :message="error.message">' + '</component>' + '</template>',
|
2566
|
+
|
2567
|
+
components: {}
|
2568
|
+
};
|
2569
|
+
|
2570
|
+
// define 'partial' prop
|
2571
|
+
errors.props['partial'] = error.props['partial'];
|
2572
|
+
|
2573
|
+
// only use ValidatorErrors component
|
2574
|
+
errors.components[error.name] = error;
|
2575
|
+
|
2576
|
+
// install ValidatorErrors component
|
2577
|
+
Vue.component(errors.name, errors);
|
2578
|
+
|
2579
|
+
return errors;
|
2580
|
+
}
|
2581
|
+
|
2582
|
+
/**
|
2583
|
+
* plugin
|
2584
|
+
*
|
2585
|
+
* @param {Function} Vue
|
2586
|
+
* @param {Object} options
|
2587
|
+
*/
|
2588
|
+
|
2589
|
+
function plugin(Vue) {
|
2590
|
+
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
2591
|
+
|
2592
|
+
if (plugin.installed) {
|
2593
|
+
warn('already installed.');
|
2594
|
+
return;
|
2595
|
+
}
|
2596
|
+
|
2597
|
+
exports$1.Vue = Vue;
|
2598
|
+
Asset(Vue);
|
2599
|
+
Errors(Vue);
|
2600
|
+
|
2601
|
+
Override(Vue);
|
2602
|
+
Validator(Vue);
|
2603
|
+
ValidateClass(Vue);
|
2604
|
+
Validate(Vue);
|
2605
|
+
}
|
2606
|
+
|
2607
|
+
plugin.version = '2.1.7';
|
2608
|
+
|
2609
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
2610
|
+
window.Vue.use(plugin);
|
2611
|
+
}
|
2612
|
+
|
2613
|
+
return plugin;
|
2614
|
+
|
2615
|
+
}));
|