Skip to content

Commit

Permalink
Update common-use-case.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest committed May 12, 2023
1 parent c5557f2 commit f3c13d6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions docs/common-use-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ const form = {
const schema = {
confirmPassword: {
$params: {
sameAsField: ['password'],
sameAsFieldPath: ['password'],
sameAsFieldName: 'Password',
},
$rules: {
sameAs({ value, params, target }) {
const anotherValue = params.sameAsField.reduce((anotherValue, key) => anotherValue[key], target)
const anotherValue = params.sameAsFieldPath.reduce((anotherValue, key) => anotherValue[key], target)
if (anotherValue !== value) {
return 'Something went wrong'
}
Expand All @@ -88,29 +88,29 @@ console.log(validator.confirmPassword.$v.errors.sameAs)

```javascript
const form = {
ipWhiteList: ['8.8.8.8', '8.8.8.8'],
ipAllowList: ['8.8.8.8', '8.8.8.8'],
}

const schema = {
ipWhiteList: {
ipAllowList: {
$iter: {
$params: {
field: 'Ip',
fieldName: 'Ip',
},
$rule: {
unique({ path, target }) {
const selfIndex = path.pop()
const parent = path.reduce((parent, key) => parent[key], target)
for (const index in parent) {
if (parent[selfIndex] === parent[index] && parseInt(index, 10) > selfIndex) {
return 'Something went wrong'
return false
}
}
},
},
$errors: {
unique({ params }) {
return `This ${params.field} is duplicated`
return `This ${params.fieldName} is duplicated`
},
},
},
Expand All @@ -122,8 +122,8 @@ const validator = {}
const proxiedForm = FormValidation.proxy({ form, schema, validator })

validator.$validate()
console.log(validator.ipWhiteList[0].$v.errors.unique)
console.log(validator.ipAllowList[0].$v.errors.unique)
// > undefined
console.log(validator.ipWhiteList[1].$v.errors.unique)
console.log(validator.ipAllowList[1].$v.errors.unique)
// > This Ip is duplicated
```

0 comments on commit f3c13d6

Please sign in to comment.