Skip to content

Display correct default value within Form #868

Answered by Roland-Hufnagel
Leon910 asked this question in Web
Discussion options

You must be logged in to vote

Hey team. Please try the following:
in EmotionForm please go back to the previous version you had before (id instead of name):

  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>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Leon910
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
2 participants