Display correct default value within Form #868
-
We are implementing the backend for our emotion tracker app. Especially we are working on the update operation. When editing an emotion on our details page the edit form opens but the respected emotion type is not pre-selected within the options bar. We are receiving the right data from our database but we are not sure how we need to apply it to the value. Here’s what I’ve tried so far:
feature/backend-update-delete-new Any help or suggestions would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey team. Please try the following: const [selectedEmotionType, setSelectedEmotionType] = useState(
defaultValue?.type.id || undefined
); Also change this part back to previous (use value instead of defaultValue): value={selectedEmotionType}
//defaultValue={defaultValue?.type.name || ""} then add the 'selected' attribute to the option: <option
key={emotion._id}
value={emotion._id}
selected={defaultValue?.type.name === emotion.name}
>
{emotion.name}
</option> |
Beta Was this translation helpful? Give feedback.
Hey team. Please try the following:
in EmotionForm please go back to the previous version you had before (id instead of name):
Also change this part back to previous (use value instead of defaultValue):
then add the 'selected' attribute to the option: