Uncaught TypeError: Cannot read property 'validateAfterLoad' of undefined
See original GitHub issueI 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:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top 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 >
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
Released
Sure, I will make a PR when I get home later today. I’m having some trouble downloading one the packages in
package.json
(thekazupon/git-commit-message-convention
one), but I think it will work from home.