我正在使用react-hook-form
。我有textarea
用户可以输入的密码pincodes
,现在我想验证我的blur
平均密码应该是6
数字并按排序顺序显示。
onblur
事件不能正常工作?这是我的代码
https://codesandbox.io/s/react-hook-form-get-started-v24jk
<TextField
inputRef={register}
label={"pincode"}
variant="outlined"
placeholder={"dd"}
multiline={true}
rows="4"
rowsMax="12"
name={"pincode"}
onBlur={v => {
console.log(v);
function onlyUnique(value, index, self) {
return self.indexOf(value) === index && value.trim().length === 6;
}
if (v) {
let codes = v.split(",");
let newCodes = codes.filter(onlyUnique);
return newCodes.sort().join(",");
}
return "";
}}
/>
反应钩子表单 API https://react-hook-form.com/api