From 5aeb14a38c17e42e6f29ceda6b7d80a80e5ca8a3 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Thu, 27 Apr 2023 17:03:43 +0200 Subject: [PATCH] :bug: Reworking select input --- .../Components/DesignSystem/Form/index.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/front/Components/DesignSystem/Form/index.tsx b/src/front/Components/DesignSystem/Form/index.tsx index e66cd454..e37ada66 100644 --- a/src/front/Components/DesignSystem/Form/index.tsx +++ b/src/front/Components/DesignSystem/Form/index.tsx @@ -1,5 +1,6 @@ import React, { ReactNode } from "react"; -import BaseField, { IError, IProps as IBaseFieldProps } from "./Elements/BaseField"; + +import BaseField, { IProps as IBaseFieldProps, IError } from "./Elements/BaseField"; export type IBaseField = BaseField; @@ -90,13 +91,25 @@ export default class Form extends React.Component { if (this.props.onValidated) this.props.onValidated(); - const elementsValues = this.getAllChildrenFields(e).reduce( + const allChildren = this.getAllChildrenFields(e); + const elementsValues = allChildren.reduce( (obj, element) => ({ ...obj, [element.getAttribute("name") ?? ""]: (element as any).value }), {}, ); + const radioInputs = allChildren.filter((e) => e.getAttribute("type") === "radio").filter((e) => (e as any).checked); + const radioInputsValues = radioInputs.reduce( + (obj, element) => ({ ...obj, [element.getAttribute("name") ?? ""]: (element as any).value }), + {}, + ); + + const allInputs = { + ...elementsValues, + ...radioInputsValues, + } + if (this.props.onSubmit) { - this.props.onSubmit(e, elementsValues, this.onSubmitErrorApi); + this.props.onSubmit(e, allInputs, this.onSubmitErrorApi); } return { values: elementsValues };