【发布时间】:2018-09-28 14:43:52
【问题描述】:
我正在尝试将输入限制为整数。我正在尝试传递直接在 HTML 中使用时似乎可以工作的 step 属性,但是很难让它从反应中传递出去。下面是我的渲染方法,数字输入在底部。我遇到的问题是输入仍然接受十进制。
render() {
const {
currentVariableValue,
type,
currentVariable,
variablePayload,
} = this.props
const lowHi = this.getLowHi()
const lowHiDisplay = `between ${lowHi[0]} and ${lowHi[1]}`
/* eslint-disable no-nested-ternary */
return (
<ResponseContainer>
{
type === 'text' ?
<TransparentTextArea
autoFocus
type="text"
value={ currentVariableValue }
onChange={ this.handleUpdateValue }
onFocus={ this.handleFocus }
onKeyPress={ this.handleKeyPress }
key={ currentVariable }
/> :
type === 'paragraph' ?
<TransparentTextArea
autoFocus
type="text"
value={ currentVariableValue }
onChange={ this.handleUpdateValue }
onFocus={ this.handleFocus }
onKeyPress={ this.handleKeyPress }
key={ currentVariable }
style={ { height: '300px', width: '95%', fontSize: '1.4em' } }
/> :
<TransparentInput
autoFocus
type="numeric"
value={ currentVariableValue }
onChange={ this.handleUpdateValue }
onFocus={ this.handleFocus }
onKeyPress={ this.handleKeyPress }
key={ currentVariable }
invalid={ !variablePayload.isValid }
step={ 1 }
/>
}
【问题讨论】:
-
>让它通过 react
-
问题是该字段仍然接受十进制值。
标签: javascript html reactjs react-templates