我一直在研究的是一个文本 input
缩小了 <option>
在 <select>
中作为用户类型。它正在运行,但我现在关心的是安全性、用户传递给 input
的内容以及潜在的恶意条目。
我想我可以做类似 <input placeholder='[a-zA-Z]' />
的事情,但它仍然允许在文本框中输入其他字符。
我在这里做错了什么,什么是只允许输入字母数字的替代方案?
onInputChange(term) {
this.setState({ term });
}
renderOptionsSelect(term) {
return _.map(this.props.pos_list, p => {
var searchTerm = this.state.term.toLowerCase();
if (p.pos_code.toLowerCase().match(searchTerm)) {
return (
<option key={p.pos_code} value={p.pos_code}>{p.pos_code}</option>
);
}
});
}
// render the main element of the container
render() {
return (
<div className='panel panel-default'>
<div className='panel-heading'>
<h4><strong>Basic Query</strong></h4>
</div>
<div className='panel-body'>
<input
pattern='[a-zA-Z]'
className='form-control'
placeholder='Enter Keyword or Position Code'
value={this.state.term}
onChange={event => this.onInputChange(event.target.value)}
/>
<hr />
<h4>Position:</h4>
<select className='form-control'>
<option></option>
{this.renderOptionsSelect()}
</select>
<br />
<h4>Data Cut:</h4>
<select className='form-control' disabled={true} />
</div>
</div>
);
}
原文由 cjones 发布,翻译遵循 CC BY-SA 4.0 许可协议
这很容易。你:
onInputChange
用于-----方法-----方法----onInput={event => this.onInputChange(event.target.value)}
input
事件 - - 事件代替change
onInputChange
中的接收值。