这是我的图式.使用Reaction-Hook-Form&Zod进行验证

const emailInputSchema = z.object({
  email: z.string().min(1, "input is required").email("email address is not valid"),
});

我希望显示消息"邮箱地址无效",而不是标准的邮箱错误消息:

enter image description here

我想要"需要输入",但我在Error对象中没有得到这个错误.

  const {
    register,
    handleSubmit,
    formState: { errors, isSubmitting },
    reset,
  } = useForm<TEmailInputSchema>({
    resolver: zodResolver(emailInputSchema, { errorMap: customErrorMap }),
  });

以下是多伦多证券交易所内部的表单:

      <form onSubmit={handleSubmit(handleMailSubmit)}>
        <div className="input-container">
          <div className="input-wrapper rounded">
            <FaRegEnvelope className="input-icon" />
            <input
              type="email"
              {...register("email")}
              placeholder="email"
              className="input"
              autoComplete="email"
            />
          </div>
        </div>
        {errors.email && (
          <p className={`${errorStyle}`}>{`${errors.email.message}`}</p>
        )}
        <div className="buttons-container">
          <button
            type="submit"
            disabled={isSubmitting}
            className="form-submit-button"
          >
            Send an email
          </button>
        </div>
      </form>

推荐答案

您需要在表单元素上使用101props .类似于:

<form onSubmit={handleSubmit(handleMailSubmit)} noValidate>
        <div className="input-container">
          <div className="input-wrapper rounded">
            <FaRegEnvelope className="input-icon" />
            <input
              type="email"
              {...register("email")}
              placeholder="email"
              className="input"
              autoComplete="email"
            />
          </div>
        </div>
        {errors.email && (
          <p className={`${errorStyle}`}>{`${errors.email.message}`}</p>
        )}
        <div className="buttons-container">
          <button
            type="submit"
            disabled={isSubmitting}
            className="form-submit-button"
          >
            Send an email
          </button>
        </div>
      </form>

Javascript相关问答推荐

如何在不分配整个数组的情况下修改包含数组的行为主体?

*ngFor和@代表输入decorator 和选角闭合

将json数组项转换为js中的扁平

Vega中的模运算符

如何避免移动设备中出现虚假调整大小事件?

vscode扩展-webView Panel按钮不起任何作用

如何从一个列表中创建一个2列的表?

获取Uint8ClampedArray中像素数组的宽度/高度

在执行异步导入之前判断模块是否已导入()

禁用.js文件扩展名并从目录导入隐式根index.js时,找不到NodeJS导入模块

为什么这个.add.group({})在教程中运行得很好,但在我的游戏中就不行了?

让chart.js饼图中的一个切片变厚?

如何在Bootstrap中减少网格系统中单个div的宽度

打字脚本中方括号符号属性访问和拾取实用程序的区别

匹配一个或多个可选重复的特定模式

使用自动识别发出信号(&Q)

React:防止useContext重新渲染整个应用程序或在组件之间共享数据而不重新渲染所有组件

在JS/TS中将复杂图形转换为数组或其他数据 struct

如何更改Html元素S的 colored颜色 ,然后将其褪色为原始 colored颜色

在范围数组中查找公共(包含)范围