所以我有自己创建的表格。当我输入“无法登录标题或说明”部分后,该表单将不会提交,否则将提交。我不太确定为什么会这样。到目前为止,我的代码如下:
const m = require('mithril')
class IssueEditor {
constructor(vnode) {
this.title = vnode.attrs.title
this.descriptionText = vnode.attrs.descriptionText
this.onSubmit = vnode.attrs.onSubmit
}
view() {
return m('form', {onsubmit: e => this.onSubmit({title: this.title, descriptionText: this.descriptionText})}, [
m('.form-group', [
m('label', {'for': 'title-input'}, 'Issue Title'),
m('input.form-control#title-input', {value: this.title, oninput: (e) => {this.title = e.target.value}})
]),
m('.form-group', [
m('label', {'for': 'description-input'}, 'Description'),
m('textarea.form-control#description-input', {oninput: (e) => {this.descriptionText = e.target.value}}, this.descriptionText)
]),
m('button.btn.btn-primary#save-button', {type: 'submit'}, 'Save')
])
}
}
答案 0 :(得分:0)
在您的onsubmit
函数中,您可能需要一个e.preventDefault()
来阻止Javascript自动提交表单,而不是使用vnode.attrs.onSubmit
函数。
所以改变
{onsubmit: e => this.onSubmit({title: this.title, descriptionText: this.descriptionText})}, [
到
{ onsubmit: e => {
e.preventDefault()
this.onSubmit({ title: this.title, descriptionText: this.descriptionText })
}}, [