如何在链接点击时获取输入字段值? [英] How to get input field value on link click?

查看:67
本文介绍了如何在链接点击时获取输入字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 json动态 生成我的表单.但是我在一个地方敲了一下,同时在点击时获取输入字段的值.

当我的演示应用程序运行时,它会显示一个输入字段(用户在其中输入手机号码)和一个按钮(文本发送 OTP).输入号码示例 (9891234178) 并按 Enter 后,它会显示 OTP 字段和链接 重新发送 OTP .

我想在点击时捕获 link(重新发送 otp)的点击处理程序我想获取我的输入字段值(手机号码值).

可以获取价值吗?

这是我的代码

我的目标是添加 link 的点击处理程序并尝试获取 mobile number 值.如果可能

有更新吗??????/

解决方案

您可能需要阅读文档的两种方法:

这个函数将返回整个表单数据,当你想要检索表单值时,它在函数中很有用.https://react-hook-form.com/api#getValues

这将监视指定的输入/输入并返回其值,这对于确定要呈现的内容很有用.https://react-hook-form.com/api#watch

I am generating my form dynamically using json.but I struck at one place while getting value of input field on click.

When My demo application run .it shows a input field ( where user enter a mobile number) and a button (text send OTP).After entering number example (9891234178) and press enter it shows OTP field and a link resend OTP .

I want to capture click handler of link (Resend otp) on click I want to get my input field value (mobile number value).

Can It is possible to get value ?

Here is my code https://codesandbox.io/s/react-hook-form-get-started-lokp2

case "link":
  return (
    <div className="form-group">
      <p className="user-link">
        <span onClick={() => {}}> {label}</span>
      </p>
    </div>
  );

my goal is to add click handler of link and try to get mobile number value. if it possible

any update?????/

解决方案

There are two methods you may want to have a read on the documentation:

This function will return the entire form data, and it's useful in a function when you want to retrieve form values. https://react-hook-form.com/api#getValues

This will watch specified input/inputs and return its value, and it's useful for determining what to render. https://react-hook-form.com/api#watch

这篇关于如何在链接点击时获取输入字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆