mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-02-17 13:20:52 +08:00
refactor(form): validate api change
This commit is contained in:
parent
ed5f61449b
commit
c015771f67
@ -76,27 +76,24 @@ export default {
|
||||
methods: {
|
||||
handlePasswordInput () {
|
||||
if (this.model.reenteredPassword) {
|
||||
this.$refs.reenteredPassword.validate('password-input', ({
|
||||
valid,
|
||||
errors
|
||||
}) => {
|
||||
if (valid) {
|
||||
this.$NMessage.success('password ok')
|
||||
this.$refs.reenteredPassword.validate('password-input', (errors => {
|
||||
if (!errors) {
|
||||
this.$NMessage.success('Valid')
|
||||
} else {
|
||||
console.log(errors)
|
||||
this.$NMessage.error('password not ok')
|
||||
this.$NMessage.error('Invalid')
|
||||
}
|
||||
})
|
||||
}))
|
||||
}
|
||||
},
|
||||
handleValidateButtonClick (e) {
|
||||
e.preventDefault()
|
||||
this.$refs.form.validate((valid, errors) => {
|
||||
console.log(valid, errors)
|
||||
if (valid) {
|
||||
this.$NMessage.success(String(valid))
|
||||
this.$refs.form.validate(errors => {
|
||||
if (!errors) {
|
||||
this.$NMessage.success('Valid')
|
||||
} else {
|
||||
this.$NMessage.error(String(valid))
|
||||
console.log(errors)
|
||||
this.$NMessage.error('Invalid')
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -212,12 +212,12 @@ export default {
|
||||
methods: {
|
||||
handleValidateButtonClick (e) {
|
||||
e.preventDefault()
|
||||
this.$refs.form.validate((valid, errors) => {
|
||||
console.log(valid, errors)
|
||||
if (valid) {
|
||||
this.$NMessage.success(String(valid))
|
||||
this.$refs.form.validate(errors => {
|
||||
if (!errors) {
|
||||
this.$NMessage.success('Valid')
|
||||
} else {
|
||||
this.$NMessage.error(String(valid))
|
||||
console.log(errors)
|
||||
this.$NMessage.error('Invalid')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -60,12 +60,12 @@ export default {
|
||||
methods: {
|
||||
handleValidateClick (e) {
|
||||
e.preventDefault()
|
||||
this.$refs.form.validate((valid, errors) => {
|
||||
if (valid) {
|
||||
this.$NMessage.success(String(valid))
|
||||
this.$refs.form.validate(errors => {
|
||||
if (!errors) {
|
||||
this.$NMessage.success('Valid')
|
||||
} else {
|
||||
console.log(errors)
|
||||
this.$NMessage.error(String(valid))
|
||||
this.$NMessage.error('Invalid')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -207,12 +207,12 @@ export default {
|
||||
methods: {
|
||||
handleValidateButtonClick (e) {
|
||||
e.preventDefault()
|
||||
this.$refs.form.validate((valid, errors) => {
|
||||
console.log(valid, errors)
|
||||
if (valid) {
|
||||
this.$NMessage.success(String(valid))
|
||||
this.$refs.form.validate(errors => {
|
||||
if (!errors) {
|
||||
this.$NMessage.success('Valid')
|
||||
} else {
|
||||
this.$NMessage.error(String(valid))
|
||||
console.log(errors)
|
||||
this.$NMessage.error('Invalid')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "naive-ui",
|
||||
"version": "0.5.18",
|
||||
"version": "0.5.19",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -209,7 +209,7 @@ export default {
|
||||
handleContentInput () {
|
||||
this._validate('input')
|
||||
},
|
||||
validate (trigger = null, afterValidate, options = null) {
|
||||
validate (trigger = null, afterValidate, options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._validate(trigger, options).then(({
|
||||
valid,
|
||||
@ -217,18 +217,13 @@ export default {
|
||||
}) => {
|
||||
if (valid) {
|
||||
if (afterValidate) {
|
||||
afterValidate({
|
||||
valid
|
||||
})
|
||||
afterValidate()
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
} else {
|
||||
if (afterValidate) {
|
||||
afterValidate({
|
||||
valid,
|
||||
errors
|
||||
})
|
||||
afterValidate(errors)
|
||||
} else {
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
reject({
|
||||
@ -239,7 +234,9 @@ export default {
|
||||
})
|
||||
})
|
||||
},
|
||||
_validate (trigger = null, options = null) {
|
||||
_validate (trigger = null, options = {
|
||||
suppressWarning: true
|
||||
}) {
|
||||
if (!this.path) {
|
||||
throw new Error('[naive-ui/form-item/validate]: validate form-item without path')
|
||||
}
|
||||
|
@ -88,12 +88,12 @@ export default {
|
||||
if (results.some(result => !result.valid)) {
|
||||
const errors = results.filter(result => result.errors).map(result => result.errors)
|
||||
if (afterValidate) {
|
||||
afterValidate(false, errors)
|
||||
afterValidate(errors)
|
||||
} else {
|
||||
reject(errors)
|
||||
}
|
||||
} else {
|
||||
if (afterValidate) afterValidate(true)
|
||||
if (afterValidate) afterValidate()
|
||||
else {
|
||||
resolve()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user