formik fieldarray textfield输入只允许一个字符在失去焦点之前
我有以下组件,并且不明白为什么我的< textfield>
输入一个字符后失去了焦点。
我已经放置了key = {index}
我认为它需要它。
如果有人能看到我缺少的东西会导致这种文本失去焦点,那就太好了。
const MyValues = ({ myGroup, name, myIndex }) => (
<FieldArray
name={name}
render={(arrayHelpers) => (
<React.Fragment>
<div className={classes.dataSourceLayout} key={myIndex}>
{myGroup.myValues.map((myValue, index) => (
<div key={index}>
<Grid
container
item
key={index}
spacing={6}>
<Grid
item
container
spacing={1}
>
<Grid item xs={5}>
<Select
name={`${name}.${index}.job`}
label='Job'
options={jobs}
/>
</Grid>
<Grid item xs={5}>
<TextField
name={`${name}.${index}.salary`}
label='Salary'
/>
</Grid>
<Grid item xs={2}>
{myGroup.myValues.length > 1 && (
<Button
disableElevation
onClick={() => arrayHelpers.remove(index)}
>
<span>Delete</span>
</Button>
)}
</Grid>
</Grid>
</Grid>
</div>
))}
</div>
</React.Fragment>
)}
/>
);
I have the following component and don't understand why my <TextField>
entry loses focus just after entering one character.
I have placed the key={index}
where I assume it needs it.
If anyone can see what I am missing to cause this textfield losing focus, that would be great.
const MyValues = ({ myGroup, name, myIndex }) => (
<FieldArray
name={name}
render={(arrayHelpers) => (
<React.Fragment>
<div className={classes.dataSourceLayout} key={myIndex}>
{myGroup.myValues.map((myValue, index) => (
<div key={index}>
<Grid
container
item
key={index}
spacing={6}>
<Grid
item
container
spacing={1}
>
<Grid item xs={5}>
<Select
name={`${name}.${index}.job`}
label='Job'
options={jobs}
/>
</Grid>
<Grid item xs={5}>
<TextField
name={`${name}.${index}.salary`}
label='Salary'
/>
</Grid>
<Grid item xs={2}>
{myGroup.myValues.length > 1 && (
<Button
disableElevation
onClick={() => arrayHelpers.remove(index)}
>
<span>Delete</span>
</Button>
)}
</Grid>
</Grid>
</Grid>
</div>
))}
</div>
</React.Fragment>
)}
/>
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你忘了在字段名称上围绕索引括起来
I guess you forgot to put parentheses around index on the fields name