Accessing parent of vm, or grandParentVm from within validator.
See original GitHub issueI have a deeply nested structure that resembles the following:
validators () {
return {
field: {
$each: {
subField: {
$each: {
subSubField: customValidator
}
}
}
}
}
}
My customValidator is as follows:
export const customValidator = (args) => {
return (0, _common.withParams)({
type: 'customValidator',
args: args
}, function (value, vm) {
// ... "vm" has limited scope, there's no way to access parent of vm
})
}
fields
can have 1 to manysubFields
subFields
can have 1 to manysubSubFields
customValidator is unable to obtain the parent of vm. This is needed for the validator within subSubField
to access a sibling property from subField
, or to access a distant relative from field
. The current scope on vm
is limited and prevents us from performing conditionals on distant relatives. Is there a way to access the parent of vm from within a validator function?
I can see 2 possible ways of implementing this.
- Add a property to the
vm
to access its parent:
export const customValidator = (args) => {
return (0, _common.withParams)({
type: 'customValidator',
args: args
}, function (value, vm) {
// ... "vm.$parent" could be used to access the "parent" of "vm"
})
}
- make $each a functional reference and pass the current index:
validators () {
return {
field: {
$each: (fieldIndex) => {
return {
subField: {
$each: (subFieldIndex) => {
return {
subSubField: customValidator
}
}
}
}
}
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
c# - Access Parent DisplayName in CustomValidator in ...
I want one custom validator ( PersonValidator ) to validate those properties. I do want to access the DisplayAttribute of those Person ...
Read more >Enabling Validation for a VM Group - Commvault Documentation
To enable validation for virtual machines that run applications, perform the following steps: In the Backup validation section, turn on the ...
Read more >Custom Validators - Vuelidate
Accessing property parent object #. If you need to create a validator, that directly needs access to a sibling property, you can use...
Read more >Vuelidate | A Vue.js model validation library
For each value you want to validate, you have to create a key inside validations options. You can specify when input becomes dirty...
Read more >Workflow "Parent Status Validator" doesn't work for "In Progress"
Can someone help me with this issue? thank you! I'm using Jira cloud. image.png.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Buddy at 8 levels, simplicity went down hill long ago 😁 BTW Vuelidate 2 removes $each, so please follow the progress, so we can get your personal experience and input on this when we release the RFC for it.
To follow up we’re deprecating vuelidate from our stack in favor of https://github.com/jquense/yup