Reactjs 反应本地文本输入;触发事件时";“完成”;受压
我使用textInput获取用户年龄,因此在iOS上,我将数字键盘和返回键类型设置为“完成”,因此我使用Reactjs 反应本地文本输入;触发事件时";“完成”;受压,reactjs,react-native,Reactjs,React Native,我使用textInput获取用户年龄,因此在iOS上,我将数字键盘和返回键类型设置为“完成”,因此我使用 returnKeyType={'done'} keyboardType="numeric" 到目前为止,我只是想弄清楚当用户点击“完成”按钮时如何做一些事情 这是我当前的文本输入字段 <TextInput placeholder="Age (Yr)" style={AuthScreenStyles.Input} aut
returnKeyType={'done'}
keyboardType="numeric"
到目前为止,我只是想弄清楚当用户点击“完成”按钮时如何做一些事情
这是我当前的文本输入字段
<TextInput
placeholder="Age (Yr)"
style={AuthScreenStyles.Input}
autoCapitalize="none"
autoCorrect={false}
returnKeyType={'done'}
keyboardType="numeric"
ref={register({ name: 'age_year' }, { required: true })}
onChangeText={(text) => setValue('age_year', text, true)}
onSubmitEditing={() => {
console.log('The button has been pressed');
}}
/>
setValue('age\u year',text,true)}
onSubmitEditing={()=>{
console.log('按钮已按下');
}}
/>
我还没有启动这个console.log()。有人知道当按下“完成”按钮时如何捕获吗?onSubmitEditing()不起作用。过去我记得它在“多行={true}中不起作用 我测试了一个警报,并使用事件本身来获取文本。应该有效:) 世博会的一个例子:
setValue('age\u year',text,true)}
onSubmitEditing={(事件)=>(Alert.Alert(event.nativeEvent.text))}
多行={false}
/>
更明确一点,@MattV的答案是正确的,请注意,如果您使用他的示例,您还需要从“React Native”导入{Alert}
但是如果您想在按下完成
按钮时使用自己的功能
,如下面的屏幕截图所示
然后您可以像这样添加onSubmitEditing
onSubmitEditing={()=>yourFunctionNameHere()}
setZip(文本)}
onSubmitEditing={()=>yourFunctionNameHere()}//
<TextInput
placeholder="Age (Yr)"
style={AuthScreenStyles.Input}
autoCapitalize="none"
autoCorrect={false}
returnKeyType={'done'}
keyboardType="numeric"
ref={register({ name: 'age_year' }, { required: true })}
onChangeText={(text) => setValue('age_year', text, true)}
onSubmitEditing = {(event) => (Alert.alert(event.nativeEvent.text))}
multiline={false}
/>
<TextInput
style={styles.textBox}
maxLength={5}
placeholder="Enter Zip Code"
placeholderTextColor={'#6D7376'}
autoCompleteType="postal-code"
keyboardType="number-pad"
returnKeyType="done"
onChangeText={text => setZip(text)}
onSubmitEditing={() => yourFunctionNameHere()} // <=== here
/>