我的想法如下:在我的网站上,用户将能够登记产品或客户。 然而,这两个表格中一个部分的登记形式显然不同。 我想让用户选择他们想要做哪些登记、客户或产品,而根据他们的选择,所介绍的领域是不同的。 如何利用反应ook形来做到这一点? 感谢!
你们应当努力这样做:
import React from react ;
import { useForm, Controller } from react-hook-form ;
function RegistrationForm() {
const { control, handleSubmit, watch } = useForm();
const selectedOption = watch( registrationType ); // Watch the dropdown value
const onSubmit = (data) => {
console.log(data);
// Handle form submission based on the selected option (customer or product)
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<div>
<label>Choose Registration Type:</label>
<Controller
name="registrationType"
control={control}
defaultValue="" // Set a default value
render={({ field }) => (
<select {...field}>
<option value="">Select...</option>
<option value="customer">Customer</option>
<option value="product">Product</option>
</select>
)}
/>
</div>
{selectedOption === customer && (
<div>
{/* Customer-specific fields */}
<label>Customer Name:</label>
<input {...register( customerName )} />
{/* Add more customer-specific fields here */}
</div>
)}
{selectedOption === product && (
<div>
{/* Product-specific fields */}
<label>Product Name:</label>
<input {...register( productName )} />
{/* Add more product-specific fields here */}
</div>
)}
<button type="submit">Submit</button>
</form>
);
}
export default RegistrationForm;
This is my first question, and english is not my first language, sorry if my question is hard to understand I was trying to make simple CRUD app with mysql database and react as the frontend, and i ...
I have two react apps, parent app and child app. and child app have an hash router. I have build the child app using npm run build, It creates build folder. That build folder moved into inside the ...
这是我的第一个问题,请与我一起回答。 I m从事一项SPA React项目,该项目跟踪农场及其相关床位,并可使用一些帮助。 我愿就......提供一些数据。
I want to print the selected value, and below is my option list: const vesselName = [ { value: 0 , label: ALBIDDA , }, { value: 1 , label: ALRUMEILA , }, { value: 2 ,...
I have this custom filter for date , filter button is working as expected but reset button is not working, can anyone help me,what s wrong here? Below is my code which contain handlesearch,handlereset ...
I am using react. I want to add a line break <br> between strings No results and Please try another search term. . I have tried No results.<br>Please try another search term. but ...
I am trying to make a POC with Rails5, action Cable, React and Rails and React DnD. The purpose is to make an app like trello but for an recruitment process. My front is in ReactJS. I have 3 ...
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding