Skip to content

Commit c46d471

Browse files
committed
fix(form): should scroll into first invalid field
1 parent e7a85a2 commit c46d471

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/components/form/form.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
this.$emit(EVENT_VALID, this.validity)
145145
this.$emit(EVENT_SUBMIT, e, this.model, this.fieldsModel)
146146
} else {
147+
// scrollToInvalidField
148+
if (this.options.scrollToInvalidField && this.firstInvalidField) {
149+
this.firstInvalidField.$el.scrollIntoView()
150+
}
147151
e.preventDefault()
148152
this.$emit(EVENT_INVALID, this.validity)
149153
}
@@ -164,11 +168,6 @@
164168
},
165169
_submit(cb) {
166170
this.validate(() => {
167-
if (this.invalid) {
168-
if (this.options.scrollToInvalidField && this.firstInvalidField) {
169-
this.firstInvalidField.$el.scrollIntoView()
170-
}
171-
}
172171
cb && cb(this.valid)
173172
})
174173
},

0 commit comments

Comments
 (0)