Skip to content

fix: leave new dropdown answers empty instead of "undefined" - #3216

Open
ihor-romaniuk wants to merge 1 commit into
openedx:masterfrom
raccoongang:ihor-romaniuk/dropdown-empty-answers
Open

fix: leave new dropdown answers empty instead of "undefined"#3216
ihor-romaniuk wants to merge 1 commit into
openedx:masterfrom
raccoongang:ihor-romaniuk/dropdown-empty-answers

Conversation

@ihor-romaniuk

@ihor-romaniuk ihor-romaniuk commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Description

Adding a dropdown problem in Studio used to fill all three answers with the word undefined. The fields look filled in, their "Enter an answer" placeholder never shows, and an author has to clear each one before typing. Every other problem type starts with empty answers.

New dropdown answers now start empty, like the rest.

Implementation notes
  • The blank dropdown template writes <option correct="True"></option>, so the parsed element has no #text. OLXParser.parseMultipleChoiceAnswers ran that through String(), which turns undefined into the string "undefined".
  • Single select and multi-select never showed it because they are in RichTextProblems: their titles are rebuilt from the preserved rich text on the very next line. Dropdown answers are plain text, so the string survived.
  • ?? '' rather than a falsy check, so an option whose text is 0 or false still parses to that value.
  • Both branches of the parser are fixed — the one for several options and the one for a single option.

Screenshot/Video

Before After
01-dropdown-before 02-dropdown-after

Testing

  1. In Studio, add a new Problem component to a unit and pick Dropdown.
  2. Expected: the three answer fields are empty and show the "Enter an answer" placeholder. Before this change each held the word undefined.
  3. Type an answer into the first field and save, then reopen the editor.
  4. Expected: the answer is what you typed.
  5. Repeat step 1 for Single select, Multi-select, Numerical input and Text input.
  6. Expected: unchanged — all of them already started empty.
  7. Open an existing dropdown problem that has answers.
  8. Expected: its answers are unchanged.

Verified locally

Check Result
New dropdown problem in the running Studio three answer fields empty with the placeholder visible; before the fix each held undefined
Parser on the blank templates dropdown now yields ["", "", ""], matching single select; before it yielded ["undefined", "undefined", "undefined"]
Regression test in OLXParser.test.js the blank dropdown template parses to three empty titles
Red/green restoring the old String() call fails exactly that test
jest src/editors/containers/ProblemEditor 44 suites, 326 tests
tsc, dprint, oxlint clean, including the stricter upstream rule set
Not verified Only the five basic problem types were checked by hand; advanced types open in the raw OLX editor and do not go through this parser path.

Adding a dropdown problem in Studio filled all three answers with the word
"undefined" instead of leaving them empty behind their "Enter an answer"
placeholder, so an author had to clear each field before typing.

The blank template writes empty option tags, and the parser turned a missing
text node into a string with String(). Single select and multi-select escape it
because they are rich text and their titles are rebuilt right after; dropdown
answers are plain text, so the string survived into the field.
@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Aug 28, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @ihor-romaniuk!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.92%. Comparing base (16e19f1) to head (1c203ff).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #3216    +/-   ##
========================================
  Coverage   95.92%   95.92%            
========================================
  Files        1397     1397            
  Lines       33581    33581            
  Branches     7947     7678   -269     
========================================
  Hits        32214    32214            
- Misses       1308     1323    +15     
+ Partials       59       44    -15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

2 participants