question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Accessing parent of vm, or grandParentVm from within validator.

See original GitHub issue

I 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 many subFields
  • subFields can have 1 to many subSubFields

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:open
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dobromir-hristovcommented, Dec 13, 2019

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.

0reactions
satkunascommented, Jan 26, 2021

To follow up we’re deprecating vuelidate from our stack in favor of https://github.com/jquense/yup

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found