API accepts choice options on a question type that has none

Open Beginner friendly
#3,981 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
api, backend

Research direction

Start at the API route for POST /ocs/v2.php/apps/forms/api/v3/forms/{formId}/questions/{questionId}/options and find the controller method that stores option texts. Read how question types are modelled and where existing type validation for questions happens, then reject option creation when the question type takes no choices. Add or extend the API test covering a short question and confirm it now returns 400 with no rows written.

Written by the indexing model from the issue text.

Description

Describe the bug

The API accepts choice options on a question type that has no choices. They are stored but never used.

Steps to reproduce
  1. Create a form with a question of type short (short text).
  2. POST /ocs/v2.php/apps/forms/api/v3/forms/{formId}/questions/{questionId}/options with {"optionTexts": ["Coffee", "Tea"]}.
Expected behaviour

400: the question type takes no options.

Actual behaviour
  1. The form still shows a text field, and the two options are stored as dead rows on the question.
Versions

Forms 5.4.2.

Dominant language
JavaScript
Stars
385
Forks
133
Avg merge
7h 54m
Merged PRs (30d)
157

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nextcloud/forms

All issues in nextcloud/forms

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.