Skip to content

Commit

Permalink
Merge pull request #3347 from LiteFarmOrg/LF-4351/Other_purpose_text_…
Browse files Browse the repository at this point in the history
…is_not_saved

LF-4351: Other purpose text is not saved
  • Loading branch information
kathyavini committed Jul 29, 2024
2 parents 4ef20db + 4d47fe1 commit 311600e
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

import { ReactNode, useRef } from 'react';
import { ReactNode, useEffect, useRef } from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { GroupBase, SelectInstance } from 'react-select';
Expand Down Expand Up @@ -101,6 +101,7 @@ const SoilAmendmentProductCard = ({
register,
watch,
setValue,
getValues,
formState: { errors },
} = useFormContext();

Expand All @@ -120,6 +121,12 @@ const SoilAmendmentProductCard = ({
selectRef?.current?.clearValue();
};

useEffect(() => {
if (otherPurposeId && !getValues(OTHER_PURPOSE_ID)) {
setValue(OTHER_PURPOSE_ID, otherPurposeId);
}
}, [otherPurposeId]);

return (
<div className={styles.productCard}>
{!isReadOnly && onRemove && (
Expand Down Expand Up @@ -181,16 +188,11 @@ const SoilAmendmentProductCard = ({
const newPurposes = e.map(({ value }) => value);
setValue(PURPOSES, newPurposes, { shouldValidate: true });
}}
style={{ paddingBottom: '12px' }} // TODO: remove after adding <QuantityApplicationRate />
style={{ paddingBottom: '12px' }}
/>
)}
/>
<input
type="hidden"
value={otherPurposeId}
defaultValue={otherPurposeId}
{...register(OTHER_PURPOSE_ID)}
/>
<input type="hidden" {...register(OTHER_PURPOSE_ID)} />

{purposes?.includes(otherPurposeId) && (
<>
Expand Down

0 comments on commit 311600e

Please sign in to comment.