vue-verify
Advanced tools
Comparing version 0.5.2 to 0.6.0
@@ -17,4 +17,6 @@ /** | ||
plugins: [ | ||
new webpack.BannerPlugin("vue-verify " + package.version + "\nbuild in " + moment().format("MMMM Do YYYY, HH:mm:ss")) | ||
new webpack.BannerPlugin("vue-verify " + package.version + | ||
"\nbuild in " + moment().format("MMMM Do YYYY, HH:mm:ss") | ||
+ "\nhttps://github.com/PeakTai/vue-verify") | ||
], | ||
} |
/*! | ||
* vue-verify 0.5.2 | ||
* build in March 24th 2016, 18:04:10 | ||
* vue-verify 0.6.0 | ||
* build in October 14th 2016, 15:15:05 | ||
* https://github.com/PeakTai/vue-verify | ||
*/ | ||
@@ -68,3 +69,14 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var buildInMethods = Vue.util.extend(__webpack_require__(1), processMethod(options.methods)) | ||
var namespace = options.namespace || "verify" | ||
var util = __webpack_require__(2) | ||
Vue.mixin({ | ||
data: function () { | ||
var obj = {} | ||
obj[namespace] = {} | ||
return obj | ||
} | ||
}) | ||
Vue.prototype.$verify = function (rules) { | ||
@@ -74,11 +86,12 @@ var vm = this | ||
var methods = Vue.util.extend(processMethod(verifier.methods), buildInMethods) | ||
var namespace = verifier.namespace || options.namespace || "verify" | ||
var verifyObj = vm[namespace] | ||
vm.$set(namespace + ".$dirty", false) | ||
vm.$set(namespace + ".$valid", false) | ||
vm.$set(namespace + ".$rules", rules) | ||
Vue.set(verifyObj, "$dirty", false) | ||
Vue.set(verifyObj, "$valid", false) | ||
Vue.set(verifyObj, "$rules", rules) | ||
Object.keys(rules).forEach(function (modelPath) { | ||
vm.$set(getVerifyModelPath(modelPath) + ".$dirty", false) | ||
verify(modelPath, vm.$get(modelPath)) | ||
var model = getVerifyModel(modelPath) | ||
Vue.set(model, "$dirty", false) | ||
verify(modelPath, util.getModel(vm, modelPath)) | ||
}) | ||
@@ -88,4 +101,5 @@ | ||
vm.$watch(modelPath, function (val) { | ||
vm.$set(getVerifyModelPath(modelPath) + ".$dirty", true) | ||
vm.$set(namespace + ".$dirty", true) | ||
var model = getVerifyModel(modelPath) | ||
Vue.set(model, "$dirty", true) | ||
Vue.set(verifyObj, "$dirty", true) | ||
verify(modelPath, val) | ||
@@ -95,5 +109,21 @@ }) | ||
function getVerifyModelPath(modelPath) { | ||
return namespace + "." + modelPath | ||
function getVerifyModel(modelPath) { | ||
var arr = modelPath.split(".") | ||
var model = verifyObj[arr[0]] | ||
if (!model) { | ||
model = {} | ||
Vue.set(verifyObj, arr[0], {}) | ||
} | ||
for (var i = 1; i < arr.length; i++) { | ||
if (!arr[i]) { | ||
continue | ||
} | ||
var m = model[arr[i]] | ||
if (!m) { | ||
m = {} | ||
Vue.set(model, arr[i], m) | ||
} | ||
model = m | ||
} | ||
return model | ||
} | ||
@@ -114,4 +144,3 @@ | ||
var ruleMapClone = Vue.util.extend({}, ruleMap) | ||
var keys = Object.keys(ruleMapClone).sort(function (a, b) { | ||
var keys = Object.keys(ruleMap).sort(function (a, b) { | ||
var m1 = methods[a] | ||
@@ -124,3 +153,3 @@ var m2 = methods[b] | ||
stepVerify(modelPath, ruleMapClone, keys, 0, val) | ||
stepVerify(modelPath, ruleMap, keys, 0, val) | ||
} | ||
@@ -153,3 +182,3 @@ | ||
else if (result instanceof Function) { | ||
var Promise = __webpack_require__(2) | ||
var Promise = __webpack_require__(3) | ||
new Promise(result).then(function () { | ||
@@ -168,6 +197,6 @@ update(modelPath, rule, false) | ||
function update(modelPath, rule, inValid) { | ||
var verifyModelPath = getVerifyModelPath(modelPath) | ||
vm.$set(verifyModelPath + "." + rule, inValid) | ||
var verifyModel = getVerifyModel(modelPath) | ||
Vue.set(verifyModel, rule, inValid) | ||
var verifyModel = vm.$get(verifyModelPath), modelValid = true | ||
var modelValid = true | ||
Object.keys(verifyModel).forEach(function (prop) { | ||
@@ -180,3 +209,3 @@ //ignore $dirty and $valid | ||
if (!modelValid) { | ||
vm.$set(verifyModelPath + "." + prop, false) | ||
Vue.set(verifyModel, prop, false) | ||
} else if (verifyModel[prop]) { | ||
@@ -187,3 +216,3 @@ modelValid = false | ||
vm.$set(verifyModelPath + ".$valid", modelValid) | ||
Vue.set(verifyModel, "$valid", modelValid) | ||
@@ -194,3 +223,4 @@ //verify.$valid | ||
for (var i = 0; i < keys.length; i++) { | ||
if (!vm.$get(getVerifyModelPath(keys[i]) + ".$valid")) { | ||
var model = getVerifyModel(keys[i]) | ||
if (!model.$valid) { | ||
valid = false | ||
@@ -200,5 +230,15 @@ break | ||
} | ||
vm.$set(namespace + ".$valid", valid) | ||
Vue.set(verifyObj, "$valid", valid) | ||
} | ||
} | ||
Vue.prototype.$verifyReset = function () { | ||
var verify = this[namespace] | ||
var rules = verify.$rules | ||
if (rules) { | ||
vm.$verify(rules) | ||
} | ||
} | ||
function processMethod(methods) { | ||
@@ -248,12 +288,2 @@ if (!methods) { | ||
Vue.prototype.$verifyReset = function () { | ||
var vm = this | ||
var verifier = vm.$options.verifier || {} | ||
var namespace = verifier.namespace || options.namespace || "verify" | ||
var rules = vm.$get(namespace + ".$rules") | ||
if (rules) { | ||
vm.$verify(rules) | ||
} | ||
} | ||
} | ||
@@ -263,3 +293,3 @@ | ||
/* 1 */ | ||
/***/ function(module, exports) { | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -388,3 +418,5 @@ /** | ||
function equalTo(val, modelPath) { | ||
return val === this.$get(modelPath) | ||
var util = __webpack_require__(2) | ||
var model = util.getModel(this, modelPath) | ||
return val === model | ||
} | ||
@@ -430,2 +462,28 @@ | ||
/* 2 */ | ||
/***/ function(module, exports) { | ||
/** | ||
* Created by peak on 2016/10/14. | ||
*/ | ||
exports.getModel = function (vm, path) { | ||
var arr = path.split(".") | ||
var model = vm[arr[0]] | ||
if (!model) { | ||
return null | ||
} | ||
for (var i = 1; i < arr.length; i++) { | ||
if (!arr[i]) { | ||
continue | ||
} | ||
var m = model[arr[i]] | ||
if (!m) { | ||
return null | ||
} | ||
model = m | ||
} | ||
return model | ||
} | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -748,9 +806,9 @@ | ||
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(3).setImmediate, __webpack_require__(5)(module))) | ||
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()), __webpack_require__(4).setImmediate, __webpack_require__(6)(module))) | ||
/***/ }, | ||
/* 3 */ | ||
/* 4 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
/* WEBPACK VAR INJECTION */(function(setImmediate, clearImmediate) {var nextTick = __webpack_require__(4).nextTick; | ||
/* WEBPACK VAR INJECTION */(function(setImmediate, clearImmediate) {var nextTick = __webpack_require__(5).nextTick; | ||
var apply = Function.prototype.apply; | ||
@@ -831,6 +889,6 @@ var slice = Array.prototype.slice; | ||
}; | ||
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3).setImmediate, __webpack_require__(3).clearImmediate)) | ||
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4).setImmediate, __webpack_require__(4).clearImmediate)) | ||
/***/ }, | ||
/* 4 */ | ||
/* 5 */ | ||
/***/ function(module, exports) { | ||
@@ -932,3 +990,3 @@ | ||
/***/ }, | ||
/* 5 */ | ||
/* 6 */ | ||
/***/ function(module, exports) { | ||
@@ -935,0 +993,0 @@ |
{ | ||
"name": "vue-verify", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "verification plugin of vue", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -8,3 +8,14 @@ /** | ||
var buildInMethods = Vue.util.extend(require("./methods.js"), processMethod(options.methods)) | ||
var namespace = options.namespace || "verify" | ||
var util = require("./util.js") | ||
Vue.mixin({ | ||
data: function () { | ||
var obj = {} | ||
obj[namespace] = {} | ||
return obj | ||
} | ||
}) | ||
Vue.prototype.$verify = function (rules) { | ||
@@ -14,11 +25,12 @@ var vm = this | ||
var methods = Vue.util.extend(processMethod(verifier.methods), buildInMethods) | ||
var namespace = verifier.namespace || options.namespace || "verify" | ||
var verifyObj = vm[namespace] | ||
vm.$set(namespace + ".$dirty", false) | ||
vm.$set(namespace + ".$valid", false) | ||
vm.$set(namespace + ".$rules", rules) | ||
Vue.set(verifyObj, "$dirty", false) | ||
Vue.set(verifyObj, "$valid", false) | ||
Vue.set(verifyObj, "$rules", rules) | ||
Object.keys(rules).forEach(function (modelPath) { | ||
vm.$set(getVerifyModelPath(modelPath) + ".$dirty", false) | ||
verify(modelPath, vm.$get(modelPath)) | ||
var model = getVerifyModel(modelPath) | ||
Vue.set(model, "$dirty", false) | ||
verify(modelPath, util.getModel(vm, modelPath)) | ||
}) | ||
@@ -28,4 +40,5 @@ | ||
vm.$watch(modelPath, function (val) { | ||
vm.$set(getVerifyModelPath(modelPath) + ".$dirty", true) | ||
vm.$set(namespace + ".$dirty", true) | ||
var model = getVerifyModel(modelPath) | ||
Vue.set(model, "$dirty", true) | ||
Vue.set(verifyObj, "$dirty", true) | ||
verify(modelPath, val) | ||
@@ -35,5 +48,21 @@ }) | ||
function getVerifyModelPath(modelPath) { | ||
return namespace + "." + modelPath | ||
function getVerifyModel(modelPath) { | ||
var arr = modelPath.split(".") | ||
var model = verifyObj[arr[0]] | ||
if (!model) { | ||
model = {} | ||
Vue.set(verifyObj, arr[0], {}) | ||
} | ||
for (var i = 1; i < arr.length; i++) { | ||
if (!arr[i]) { | ||
continue | ||
} | ||
var m = model[arr[i]] | ||
if (!m) { | ||
m = {} | ||
Vue.set(model, arr[i], m) | ||
} | ||
model = m | ||
} | ||
return model | ||
} | ||
@@ -54,4 +83,3 @@ | ||
var ruleMapClone = Vue.util.extend({}, ruleMap) | ||
var keys = Object.keys(ruleMapClone).sort(function (a, b) { | ||
var keys = Object.keys(ruleMap).sort(function (a, b) { | ||
var m1 = methods[a] | ||
@@ -64,3 +92,3 @@ var m2 = methods[b] | ||
stepVerify(modelPath, ruleMapClone, keys, 0, val) | ||
stepVerify(modelPath, ruleMap, keys, 0, val) | ||
} | ||
@@ -107,6 +135,6 @@ | ||
function update(modelPath, rule, inValid) { | ||
var verifyModelPath = getVerifyModelPath(modelPath) | ||
vm.$set(verifyModelPath + "." + rule, inValid) | ||
var verifyModel = getVerifyModel(modelPath) | ||
Vue.set(verifyModel, rule, inValid) | ||
var verifyModel = vm.$get(verifyModelPath), modelValid = true | ||
var modelValid = true | ||
Object.keys(verifyModel).forEach(function (prop) { | ||
@@ -119,3 +147,3 @@ //ignore $dirty and $valid | ||
if (!modelValid) { | ||
vm.$set(verifyModelPath + "." + prop, false) | ||
Vue.set(verifyModel, prop, false) | ||
} else if (verifyModel[prop]) { | ||
@@ -126,3 +154,3 @@ modelValid = false | ||
vm.$set(verifyModelPath + ".$valid", modelValid) | ||
Vue.set(verifyModel, "$valid", modelValid) | ||
@@ -133,3 +161,4 @@ //verify.$valid | ||
for (var i = 0; i < keys.length; i++) { | ||
if (!vm.$get(getVerifyModelPath(keys[i]) + ".$valid")) { | ||
var model = getVerifyModel(keys[i]) | ||
if (!model.$valid) { | ||
valid = false | ||
@@ -139,5 +168,15 @@ break | ||
} | ||
vm.$set(namespace + ".$valid", valid) | ||
Vue.set(verifyObj, "$valid", valid) | ||
} | ||
} | ||
Vue.prototype.$verifyReset = function () { | ||
var verify = this[namespace] | ||
var rules = verify.$rules | ||
if (rules) { | ||
vm.$verify(rules) | ||
} | ||
} | ||
function processMethod(methods) { | ||
@@ -187,12 +226,2 @@ if (!methods) { | ||
Vue.prototype.$verifyReset = function () { | ||
var vm = this | ||
var verifier = vm.$options.verifier || {} | ||
var namespace = verifier.namespace || options.namespace || "verify" | ||
var rules = vm.$get(namespace + ".$rules") | ||
if (rules) { | ||
vm.$verify(rules) | ||
} | ||
} | ||
} |
@@ -123,3 +123,5 @@ /** | ||
function equalTo(val, modelPath) { | ||
return val === this.$get(modelPath) | ||
var util = require("./util.js") | ||
var model = util.getModel(this, modelPath) | ||
return val === model | ||
} | ||
@@ -126,0 +128,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
133542
13
1445