Skip to content

fix(api): add options only to questions that take them - #4000

Open
AndyScherzinger wants to merge 2 commits into
mainfrom
fix/options-only-for-choice-questions
Open

AndyScherzinger wants to merge 2 commits into
mainfrom
fix/options-only-for-choice-questions

Conversation

@AndyScherzinger

Copy link
Copy Markdown
Member

Problem

POST /api/v3/forms/{formId}/questions/{questionId}/options checked the form and that the question belongs to it, but not the question type. Options could be added to short text, long text, date, time, color, file and linear scale questions, which have no choices. They were stored as dead rows: never shown, never used. The option type was not checked either, so a dropdown could get grid row options or a grid choice options.

Fixes #3981

Change

ApiController::newOption() now accepts options only for question types that use them:

  • dropdown, multiple, multiple_unique and ranking: option type choice
  • grid: option type row or column

Any other question type gets 400 "This question type takes no options", and an option type that does not fit the question gets 400 "Invalid option type for this question". A missing or null option type still means choice, as documented. Options that are already stored stay untouched. docs/API_v3.md, docs/DataStructure.md (ranking uses choice too) and openapi.json are updated.

How to verify

  1. Create a form with a short text question and a radio button question.
  2. POST …/questions/{shortQuestionId}/options with {"optionTexts": ["Coffee", "Tea"]}: 400, and the question still has no options.
  3. The same request on the radio button question: 201, as before.
  4. In the editor, adding options to dropdown, checkbox, radio button, ranking and grid questions works as before.

Unit test testNewOptionOptionType covers every combination of question type and option type above, and the integration test testCreateNewOptionRejectsQuestionWithoutOptions covers the request from the issue.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@AndyScherzinger AndyScherzinger added this to the 5.5 milestone Nov 23, 2026
@AndyScherzinger AndyScherzinger added bug Something isn't working backport-request Pending backport by the backport-bot 3. to review Waiting for reviews feature: ❓ question types AI assisted labels Nov 23, 2026
@AndyScherzinger

Copy link
Copy Markdown
Member Author

/backport to stable5.4

@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Chartman123 Chartman123 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments mainly about organizing our constants

Comment thread lib/Controller/ApiController.php Resolved
Comment thread lib/Db/Option.php Resolved
The option types row and column were defined on the Option entity,
while the question types, grid cell types and the other shared values
live in Constants. Moving them there keeps the types an option can
have next to the question types that use them.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
The endpoint that creates options checked the form and the question,
but not the question type, so options could be stored on short text,
date, file, linear scale and other questions that have no choices.
They were never shown or used and stayed as dead rows. The option
type was not checked either, so a dropdown could get grid rows.

Options are now accepted only for dropdown, checkbox, radio button and
ranking questions (option type choice) and for grid questions (row or
column), and are otherwise rejected with 400. A missing option type
still means choice.

Fixes #3981

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@AndyScherzinger
AndyScherzinger force-pushed the fix/options-only-for-choice-questions branch from bfdca39 to 142c37a Compare November 23, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews AI assisted backport-request Pending backport by the backport-bot bug Something isn't working feature: ❓ question types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API accepts choice options on a question type that has none

2 participants