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.

Dynamic validation schema not updating when optionMergeStrategy defined

See original GitHub issue

Hi, I have a mixin where I load validation rules from my backend and assign them to the data property in the created hook. This works as expected. Now I want to expand these validation rules in my components at will. I wrote a customMergeStrategy to merge the two validation rules, but it seems like this disables the behavior of the validations () function, because it does not jump into it when I do the following in created:

this.validationRules = {
    required,
    minLength: minLength(5)
}

I expected it to jump in the validations() function and to return the correct validation rules: return { text: this.validationRules }

Am I missing a point or is this a bug?

Here is a fiddle which shows my problem (without the mixin and with the customMergeStrategy doing nothing but returning the validation object to keep things as simple as possible): https://jsfiddle.net/LarsRip/hy0joanc/8/

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
RipkensLarcommented, Feb 28, 2019

Found the solution: You can simply use the merge strategy from data: Vue.config.optionMergeStrategies.validations = Vue.config.optionMergeStrategies.data

Working fiddle: https://jsfiddle.net/zw6d5bp9/

0reactions
hiravebapucommented, Feb 13, 2019

@kosanr1 when you define rules on backend what kind of data format are you using: example

{
      serial_number: {
        required,
        minLength: minLength(4),
      },
      device_id: {
        minLength: minLength(10),
      },
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create an Optional Dynamic Validation Schema based ...
In this lesson we'll show how to setup a nested validation structure using the `yup` library. We'll then use the `yup.lazy` method to...
Read more >
Create dynamic Yup validation schema from JSON
In case someone is trying to create yupschema on the fly. With some help, I was able to do it. import * as...
Read more >
Create an Optional Dynamic Validation Schema based on a ...
In this lesson we'll show how to setup a nested validation structure using the yup library. We'll then use the yup.lazy method to...
Read more >
Dynamic Formik Validation - DEV Community ‍ ‍
The state of the initial values and validation schema can then be updated accordingly so that the useFormik hook now has the right...
Read more >
Dynamic Rules - VeeValidate
Meaning not only you can create very versatile form validation rules but you can dynamically apply them. So you can do the following:....
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