1

What I am trying to do is this:

validateStep(stepNumber) {
  const self = this;
  this.$v.registration_step${stepNumber}.touch()

  if (this.$v.registration_step${stepNumber}.$error) {
    this.$q.notify('Controleer aub de velden opnieuw');
    return;
  }
  self.$refs.stepper.next();
},

But this isn't working. As you can see I want to call .touch() on a dynamic variable depending on what step the user is currently in (so it would become this.$v.registration_step1.touch() if the user is currently in step 1.

How would you do this?

2 Answers 2

2

try accessing the key in another way:

this.$v[`registration_step${stepNumber}`].touch()
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, this doesn't seem to work. I get this: TypeError: this.$v.registration["".concat(...)].touch is not a function note: I refactored the registration object so my code now is this: validateStep(stepNumber) { const self = this; const step = step${stepNumber}; console.log(step); this.$v.registration[${step}].touch(); if (this.$v.registration[${step}].$error) { this.$q.notify('Controleer aub de velden opnieuw'); return; } self.$refs.stepper.next(); },
nvm you solution works. problem was that I was calling .touch instead of .$touch which was not relevant to this issue. Accepted your answer.
-1
this.$v['registration_step' + stepNumber].touch()

1 Comment

Also it doesn't seem to work. It states that it can't call .touch of undifined. I reworked to code to this: ` validateStep(stepNumber) { const self = this; const step = step${stepNumber}; console.log(this.$v.registration[step]); const currentStep = this.$v.registration[step]; currentStep.touch(); if (currentStep.$error) { this.$q.notify('Controleer aub de velden opnieuw'); return; } self.$refs.stepper.next(); },` But still no luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.