reactjs - 当我更改 Formik React js 中自动清除的另一个表单元素自动完成值时
问题描述
表单有两个元素。
当我从emal
元素中选择自动完成值,然后尝试向titl
字段输入文本值时,自动完成值会自动更改为空。
我应该怎么做才能解决这个问题?
我试图改变formik
initialValues
使用状态,但它不起作用。
抱歉语言问题。提前致谢!
class TicketNew extends React.Component{
state = {
clearForm:false,
spinner:false,
closeForm:false,
emailsugges:[],
}
loadAlldata() {
this.setState({
spinner:false,
})
axios.post(baseUrl+'/api/load_company_list')
.then(res => {
const comanyList = res.data;
const emls = comanyList.emls.map(function(item, i){
return {
value:item.tci, title:item.tcc
}
})
this.setState({
emailsugges:emls
})
})
this.setState({
spinner:false,
})
};
componentDidMount(){
this.loadAlldata();
};
render(){
return(
<React.Fragment>
<Formik
initialValues={{ emal: "", titl: "" }}
validationSchema={formSchema}
>
{
({ errors,
touched,
handleSubmit,
isSubmitting,
handleBlur,
values,
resetForm
}) => (
<div>
<Form onSubmit={handleSubmit}>
<Card>
<CardHeader></CardHeader>
<CardBody>
<Row>
<Col md="5" sm="12">
<FormGroup row className="position-relative">
<Col md="4">
<span>Title</span>
</Col>
<Col md="8">
<Field
type="text"
name="titl"
id="titl"
className={`
form-control ${errors.titl && touched.titl && "is-invalid"}
`}
onBlur={handleBlur('titl')}
/>
{errors.titl &&
touched.titl ? (
<div className="invalid-tooltip mt-25">
{errors.titl}
</div>
) : null}
</Col>
</FormGroup>
</Col>
<Col md="2" sm="12"></Col>
<Col md="5" sm="12">
<FormGroup row className="position-relative"
style={{display:rqst!="1"?'none':''}}
>
<Col md="4">
<span>Email Address</span>
</Col>
<Col md="8">
<Field name="emal"
component={ ({field, form}) =>
<AutoComplete
type="email"
name="emal"
id="emal"
suggestions={this.state.emailsugges}
value={
this.state.emailsugges ?
this.state.emailsugges.find(option =>
option.value === field.value)
: ''}
className={`
form-control ${errors.emal && touched.emal && "is-invalid"}
`}
filterKey="title"
suggestionLimit={4}
/>}
/>
{errors.emal &&
touched.emal ? (
<div className="invalid-tooltip mt-25">
{errors.emal}
</div>
) : null}
</Col>
</FormGroup>
</Col>
</Row>
</CardBody>
</Card>
</Form>
</div>
)}
</Formik>
</React.Fragment>
)
}
};
export default TicketNew;
解决方案
推荐阅读
- python - 解析破折号连接多个值的字段
- visual-studio - Visual Studio 的 PowerShell 工具,但收到数字签名无效时间戳错误
- bash - 针对来自终端的参数列表执行 shell 脚本
- c++ - 从 c++ windows 应用程序排列监视器
- callback - 来自按钮 n_clicks 的回调卡片颜色
- c# - Entity Framework Core,如何为 .HasOptional 配置可空外键等效项
- c# - C#soap 调用正在生成 HEAD 请求并且外部服务器正在阻塞。如何去除这些?
- node.js - 如何在不需要刷新页面的情况下与区块链交互
- azure - Azure.Data.Table 无法初始化 TableClient 或 TableServerClient
- regex - 正则表达式在 O365 传输规则中不起作用