From aa5cea7ec948850062a537dde2691829f9897d52 Mon Sep 17 00:00:00 2001 From: Hagan Date: Tue, 11 Sep 2018 16:41:06 +0800 Subject: [PATCH 1/3] fix(validatable.js): add skipValidate add skipValidate --- src/components/form/index.md | 39 +++++++++++++++++++++++++ src/entry.js | 2 +- src/scripts/mixins/validatable/index.js | 7 +++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/components/form/index.md b/src/components/form/index.md index 09d99f17..4b096a9c 100644 --- a/src/components/form/index.md +++ b/src/components/form/index.md @@ -666,6 +666,45 @@ new Vue({ } }) ``` +## 跳过组件验证 + +在复杂的业务场景下,我们自定义了一些表单组件以便于组件的复用,我们在自定义组件中做了验证规则,然后我们在各处调用该组件,但在某些场景下调用该组件并不需要执行验证操作,这时我们可以添加skipValidate属性来跳过本次组件的验证功能 + +```html + + + + + + + + 提交 + + + +``` ## 属性说明 diff --git a/src/entry.js b/src/entry.js index 6d801127..4f861760 100644 --- a/src/entry.js +++ b/src/entry.js @@ -2,7 +2,7 @@ import { Clair } from './scripts' // import './styles/entry.css' if (typeof window !== 'undefined' && window.Vue) { - window.Vue.use(Clair) + // window.Vue.use(Clair) } export default Clair diff --git a/src/scripts/mixins/validatable/index.js b/src/scripts/mixins/validatable/index.js index a1402829..a052706e 100644 --- a/src/scripts/mixins/validatable/index.js +++ b/src/scripts/mixins/validatable/index.js @@ -15,7 +15,8 @@ export default { validateThrottle: { type: Number, default: 0 - } + }, + skipValidate: Boolean }, data () { @@ -26,7 +27,7 @@ export default { msg: '', dirty: false }, - isValidatable: true, + isValidatable: !this.skipValidate, // id of the latest validation validationId: 0 } @@ -83,7 +84,7 @@ export default { validate () { this.validity.dirty = true const { $formItem, builtinRules } = this - const required = $formItem && !this.$parent.isValidatable && $formItem.required + const required = $formItem && !this.$parent.isValidatable && $formItem.required && this.isValidatable const rules = Object.assign({ required }, builtinRules, this.rules) if (!rules.msg) rules.msg = {} if (typeof rules.msg === 'object' && !rules.msg.required) { From 316e4cbdceccef7572471776d9c0c1d6402dc094 Mon Sep 17 00:00:00 2001 From: Hagan Date: Tue, 11 Sep 2018 17:21:56 +0800 Subject: [PATCH 2/3] fix(select.vue): @change add label parameter @change add label parameter --- src/components/select/index.md | 5 ++++- src/components/select/index.vue | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/select/index.md b/src/components/select/index.md index 3a701a14..ee5ec4be 100644 --- a/src/components/select/index.md +++ b/src/components/select/index.md @@ -491,20 +491,23 @@ export default { 某些场景下,你会需要根据用户的输入从服务器端获取相关选项。你可以指定 `filter` 函数返回一个 `Promise` 即可。使用 `filter` 函数时,可以通过 `filterThrottle` 指定最小触发间隔,其默认值为 `0`。 ```html +