我在我的Meteor React應用程序中遇到了這個錯誤。長話短說:我有一個表單來創建一個事件,我希望handleSubmit()來處理錯誤消息,如果沒有,向db添加事件。我確實導入了{Events},事實上這個表單在我做了一些修改之前就已經工作了。當我運行它時,我收到一條錯誤消息:Uncaught TypeError:event.target [matches]不是函數。拋出錯誤的文件不幸的是對我來說很亂。表單提交錯誤
這裏是我的代碼:
export default class Create extends React.Component {
constructor(props) {
super(props);
this.state = {
error: {}
}
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(evt) {
evt.preventDefault();
this.setState({error: {}});
let title = this.refs.title.value;
if (!title) {
this.setState((prevState) => {
let newState = prevState;
newState.error.title = 'Title has to be filled up.';
return newState;
})
}
let description = this.refs.description.value;
if (!description) {
this.setState((prevState) => {
let newState = prevState;
newState.error.description = 'Description has to be filled up.';
return newState;
})
}
if (!this.state.error) {
Events.insert({title: title, description: description});
this.props.history.push('/home');
}
和我的html:
<form onSubmit={this.handleSubmit} noValidate>
<input ref="title" type="text" name="title" placeholder="Title"
style={this.state.error.title ? {borderBottomColor: 'red'} : undefined}/>
<div className="errorText">{this.state.error.title}</div>
<input ref="description" type="text" name="description" placeholder="Description"
style={this.state.error.description ? {borderBottomColor: 'red'} : undefined}/>
<div className="errorText">{this.state.error.description}</div>
<button type="submit" className="btn btn-success">Create new event</button>
</form>
可惜我不能進行該項目,直到這個錯誤解決了,所以我會很高興,如果有人幫我!
最佳,
嗨,湯姆,謝謝你花時間。它是重複的。另一個是沒有答案......我等了30分鐘沒有一個新的觀點,所以我猜它已經死了,問題仍然相關。你可以取消你的失敗,因爲它沒有幫助。最好的, –