Skip to content

Commit aa32c32

Browse files
committed
fix(validation): unmount causes null ref
1 parent 8dfba2a commit aa32c32

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/formGenerator.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ export default {
240240
* @private
241241
*/
242242
_validateChild (child) {
243+
if (!child) return
244+
243245
if (this.options.validateAsync) {
244246
child.validate().then(function (errors) {
245247
if (errors[0]) {
@@ -284,10 +286,10 @@ export default {
284286
let fields = []
285287
let results = []
286288
287-
forEach(this.$refs.children, child => {
288-
if (isFunction(child.validate)) {
289-
fields.push(child.$refs.child) // keep track of validated children
290-
results.push(child.$refs.child.validate(true))
289+
this.$refs.children.forEach(child => {
290+
if (child && isFunction(child.validate)) {
291+
fields.push(child)
292+
results.push(child.validate(true))
291293
}
292294
})
293295

src/formGroup.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import { get as objGet, isNil, isFunction } from 'lodash'
6363
import { slugifyFormID } from './utils/schema'
6464
import formMixin from './formMixin.js'
6565
import * as fieldComponents from './utils/fieldsLoader'
66-
import { ref } from 'vue'
6766
6867
export default {
6968
name: 'FormGroup',
@@ -89,11 +88,6 @@ export default {
8988
}
9089
}
9190
},
92-
data() {
93-
return {
94-
child: ref()
95-
}
96-
},
9791
computed: {
9892
hasIconBefore () {
9993
return this.field.labelIcon && this.field.labelIcon.iconClass && this.field.labelIcon.position === 'before'
@@ -180,7 +174,9 @@ export default {
180174
this.$emit('modelUpdated', newVal, schema)
181175
},
182176
validate(calledParent) {
183-
return this.$refs.child.validate(calledParent)
177+
if (this.$refs.child) {
178+
return this.$refs.child.validate(calledParent)
179+
}
184180
},
185181
clearValidationErrors() {
186182
if (this.$refs.child) {

0 commit comments

Comments
 (0)