Merge pull request #5 from Infrastructure/feature/form

fix: cannot exec validate rules in the multiple select
This commit is contained in:
jintao-gan 2019-08-01 17:51:47 +08:00 committed by GitHub Enterprise
commit c0f6e05f18
3 changed files with 59 additions and 3 deletions

View File

@ -306,6 +306,17 @@
:items="items" :items="items"
/> />
</n-form-item> </n-form-item>
<n-form-item
prop="mutiSelect.0"
label="Select"
>
<n-select
v-model="validateForm.mutiSelect[0]"
multiple
placeholder="Please Select Type"
:items="items"
/>
</n-form-item>
<n-form-item <n-form-item
label="Switch" label="Switch"
prop="switch" prop="switch"
@ -362,6 +373,17 @@
:items="items" :items="items"
/> />
</n-form-item> </n-form-item>
<n-form-item
prop="mutiSelect.0"
label="Select"
>
<n-select
v-model="validateForm.mutiSelect[0]"
multiple
placeholder="Please Select Type"
:items="items"
/>
</n-form-item>
<n-form-item label="Switch" prop="switch"> <n-form-item label="Switch" prop="switch">
<n-switch v-model="validateForm.switch" /> <n-switch v-model="validateForm.switch" />
</n-form-item> </n-form-item>
@ -390,6 +412,13 @@
<script> <script>
export default { export default {
data () { data () {
let arrayValidate = (rule, value, callback) => {
if (value.length <= 0) {
callback(new Error('input required'))
} else {
callback()
}
}
return { return {
validateForm: { validateForm: {
input: "", input: "",
@ -406,6 +435,9 @@
input: [ input: [
{ required: true, message: "input cannot be empty", trigger: "blur" } { required: true, message: "input cannot be empty", trigger: "blur" }
], ],
'mutiSelect.0': [
{ validator: arrayValidate, trigger: 'change' }
],
"muti.deep.select": [ "muti.deep.select": [
{ {
required: true, required: true,
@ -708,6 +740,13 @@ export default {
callback() callback()
} }
} }
var arrayValidate = (rule, value, callback) => {
if (value.length <= 0) {
callback(new Error('input required'))
} else {
callback()
}
}
return { return {
form: { form: {
name: '', name: '',
@ -745,6 +784,9 @@ export default {
select: 'Public' select: 'Public'
} }
}, },
mutiSelect: [
[]
],
datepicker: 0, datepicker: 0,
switch: false, switch: false,
radio: '' radio: ''
@ -753,6 +795,9 @@ export default {
input: [ input: [
{ required: true, message: 'input cannot be empty', trigger: 'blur' } { required: true, message: 'input cannot be empty', trigger: 'blur' }
], ],
'mutiSelect.0': [
{ validator: arrayValidate, trigger: 'change' }
],
'muti.deep.select': [ 'muti.deep.select': [
{ {
required: true, required: true,

View File

@ -134,6 +134,7 @@ import toggleable from '../../../mixins/toggleable'
import zindexable from '../../../mixins/zindexable' import zindexable from '../../../mixins/zindexable'
import Scrollbar from '../../Scrollbar' import Scrollbar from '../../Scrollbar'
import clickoutside from '../../../directives/clickoutside' import clickoutside from '../../../directives/clickoutside'
import Emitter from '../../../mixins/emitter'
export default { export default {
name: 'NMultipleSelect', name: 'NMultipleSelect',
@ -144,11 +145,16 @@ export default {
directives: { directives: {
clickoutside clickoutside
}, },
mixins: [detachable, toggleable, placeable, zindexable], mixins: [detachable, toggleable, placeable, zindexable, Emitter],
model: { model: {
prop: 'selectedValue', prop: 'selectedValue',
event: 'input' event: 'input'
}, },
inject: {
formItem: {
default: null
}
},
props: { props: {
items: { items: {
type: Array, type: Array,
@ -227,6 +233,12 @@ export default {
} else { } else {
this.label = '' this.label = ''
} }
},
selectedItems (n) {
if (this.formItem) {
let vals = n.map(i => i.value)
this.dispatch('NFormItem', 'on-form-change', vals)
}
} }
}, },
methods: { methods: {

View File

@ -69,8 +69,7 @@
} }
.n-form-item__validate { .n-form-item__validate {
position: absolute; position: absolute;
bottom: -18px; bottom: -22px;
margin-top: 6px;
color: rgba(255, 146, 164, 1); color: rgba(255, 146, 164, 1);
font-size: 14px; font-size: 14px;
} }