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.

Uncaught TypeError: Cannot read property 'validateAfterLoad' of undefined

See original GitHub issue

I get this error when I try to use the VueFormGenerator component without passing in an options property. For example,

<template>
    <vue-form-generator :schema="schema" :model="model"></vue-form-generator>
</template>

<script>
import { component as VueFormGenerator } from 'vue-form-generator';

export default {
    components: {
        VueFormGenerator,
    },

    data() {
        return {
            schema: {
                fields: [
                    { model: 'foo', type: 'number' },
                ],
            },
            model: {
                foo: 3.14,
            },
        },
    },
};
</script>

The bug is in the watch method in src/formGenerator.vue, where the library does not check if this.options is truthy before checking if this.options.validateAfterLoad is true. Reference.

There are two potential solutions to this problem: either set default values for the options property or add an additional check for this.options before access this.options.validateAfterLoad.


To set a default value, the library could define its props as:

<script>
export default {
    props: {
        schema: Object,
        options: {
            type: Object,
            default: {
                validateAfterLoad: false,
            },
        },
        // etc
    },
};
</script>

To just add the extra check, the code would need to change from:

// Model changed!
if (this.options.validateAfterLoad === true && this.isNewModel !== true)
    this.validate();
else
    this.clearValidationErrors();

to:

// Model changed!
if (this.options && this.options.validateAfterLoad === true && this.isNewModel !== true)
    this.validate();
else
    this.clearValidationErrors();

so that it matches the line later in the same file: Reference:

// First load, running validation if neccessary
if (this.options && this.options.validateAfterLoad === true && this.isNewModel !== true)
    this.validate();
else
    this.clearValidationErrors();

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
icebobcommented, Nov 14, 2016

Released

1reaction
player1537commented, Nov 1, 2016

Sure, I will make a PR when I get home later today. I’m having some trouble downloading one the packages in package.json (the kazupon/git-commit-message-convention one), but I think it will work from home.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'validate' of undefined
I am trying to validate my registration form but I'm getting this error and I can't solve it. my form submit button goes...
Read more >
TypeError: Cannot read property 'validate' of undefined? - React
“Cannot read property 'validate' of undefined”? Anyone can help in finding the error. ... Is there any more to that error? For example...
Read more >
TypeError: Cannot read property 'validate' of undefined #2291
I am getting the error TypeError: Cannot read property 'validate' of undefined when running a chai-enzyme test, followed by the warning: ...
Read more >
Cannot read property 'querySelector' of null - Syncfusion
I have two pivot views below each other. When the data load the spinner shows but doesn't go away after load and I...
Read more >
Uncaught TypeError: Cannot read property 'mode' of undefined
Uncaught TypeError : Cannot read property 'mode' of undefined ... Thanks for your help in advance!. Some error in console after clicking submit...
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