I have problem with validation of product item. Since it has onChange hook, the state of product field is always error. Somehow the value of the select is not set correctly.
I want to create Issue Panel with some complex input mask.
const productList = [
{ label: "Product1", value: 5, specialTreatments: [{ label: "Treatment1", value: 1 },{ label: "Treatment2", value: 2 }] },
{ label: "Product2", value: 9, specialTreatments: [] } ];
const [specialTreatmentsItems, setspecialTreatmentsItems] = useState([]);
const productEntryChanged = (event) => {
setspecialTreatmentsItems(event.specialTreatments);
};
return (<>
<Form>
<FormSection>
<Stack grow="fill">
<Label labelFor={getFieldId("product")}>Produkt<RequiredAsterisk /></Label>
<Select {...register("product", { required: 'Error Text'})} options={productList} onChange={productEntryChanged}></Select>
</Stack>
<Stack grow="fill">
<Label labelFor={getFieldId("SpecialTreatments")}>Sonderbehandlung</Label>
<Select {...register("SpecialTreatments")} options={specialTreatmentsItems} isClearable></Select>
</Stack>
</FormSection>
</Form>
</>);
add value property
const [product, setProduct] = useState({});
const productEntryChanged = (event) => {
setspecialTreatmentsItems(event.specialTreatments);
setProduct(event);
};
...
<Select {...register("product", { required: 'Error Text' })} options={productList} onChange={productEntryChanged} value={product}></Select>
The input is being set, but validation still on error state. Removing onChange event resolves the problem, but i need to set special treatments depends on product