Skip to content

fix(submission): accept a linear scale answer only as its plain number - #3977

Merged
AndyScherzinger merged 1 commit into
mainfrom
fix/scale-answer-plain-number
Nov 21, 2026
Merged

AndyScherzinger merged 1 commit into
mainfrom
fix/scale-answer-plain-number

Conversation

@AndyScherzinger

@AndyScherzinger AndyScherzinger commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Stack

Part 1 of 3 of the linear scale stack. Merge in this order:

  1. fix(submission): accept a linear scale answer only as its plain number #3977 (this PR) fix(submission): accept a linear scale answer only as its plain number
  2. feat(linearscale): rating sub type with stars, hearts or thumbs #3978 feat(linearscale): rating sub type with stars, hearts or thumbs
  3. feat(results): average, median, range and a promoter score sub type for scale questions #3635 promoter score sub type and scale figures

This PR targets main. #3978 builds on it, so it merges first.

Screenshots (stacked PR)

👀 🌞 🌚
Editor forms-linear-scale-editor-light forms-linear-scale-editor-dark
Results forms-linear-scale-results-light forms-linear-scale-results-dark
Public link forms-linear-scale-public-link-light forms-linear-scale-public-link-dark
Embedded form forms-linear-scale-embedded-form-light forms-linear-scale-embedded-form-dark

A linear scale answer passed the server's check when it was written with leading zeros ("05") or as a JSON number with a fraction part (4.0), because the check only looked at the digits of the value cast to a string. "05" was stored as sent: the results summary then counted it as a value of its own next to 5, and exports showed it as written. 4.0 was stored as "4".

The check now reads the answer with normalizeNumericOptionId(), the helper that already reads option ids of choice questions, so a linear scale answer follows the same plain-number rule: a number, or a string of exactly its digits. Valid answers (3, "3", "0" on a 0-based scale) are accepted as before, and booleans and lists are still rejected. For API clients that send "05" or 4.0 this changes behaviour: they now get a 400 that names the rule. Answers already stored are not affected. docs/API_v3.md now describes the accepted form of a linear scale answer.

The submit page restores a linear scale answer from a draft or from an edited response as its plain number as well (withOfferedValues() in Submit.vue), so a response stored with "05" before this change can still be edited and saved instead of being rejected.

Split out of #3637, where it was found while reviewing the rating question, which now builds on the linear scale.

How to verify

Submit {"answers": {"<scale question id>": ["05"]}} to a form with a linear scale (POST /ocs/v2.php/apps/forms/api/v3/forms/{formId}/submissions): it is now rejected with 400 "The answer for question … must be a whole number from 1 to 5, written without leading zeros or a decimal point." The same goes for [4.0]; ["4"] and [4] are accepted. SubmissionServiceTest covers the rejected forms and the accepted ones at both bounds, submit-form.spec.ts checks that a draft with "05" is sent as "5", and all of it was checked against a Nextcloud 35 test instance.

🤖 AI (if applicable)

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

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread lib/Service/SubmissionService.php Resolved
@AndyScherzinger
AndyScherzinger force-pushed the fix/scale-answer-plain-number branch from fa31015 to eb66419 Compare November 21, 2026 19:44
@AndyScherzinger AndyScherzinger added bug Something isn't working feature: 📝 submitting responses and removed enhancement New feature or request labels Nov 21, 2026
Comment thread lib/Service/SubmissionService.php Resolved
Comment thread src/views/Submit.vue Resolved
Comment thread lib/Service/SubmissionService.php Resolved
Comment thread src/views/Submit.vue Resolved
The check of a linear scale answer accepted "05" and the JSON number
4.0, as ctype_digit() only looked at the digits of the value cast to a
string. "05" was stored as sent, so the results counted it as a value
of its own next to "5", and exports showed it as written. 4.0 was
stored as "4".

The check now reads the answer with normalizeNumericOptionId(), so a
linear scale answer follows the same plain-number rule as the option
ids of choice questions: a number, or a string of exactly its digits.
For API clients that send "05" or 4.0 this changes behaviour: they get
an error that names the rule. Answers already stored are not affected.

The submit page restores a scale answer from a draft or from an edited
response as its plain number as well, so an answer stored as "05"
before is sent back as "5" instead of being rejected.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@AndyScherzinger
AndyScherzinger force-pushed the fix/scale-answer-plain-number branch from eb66419 to 3b2e625 Compare November 21, 2026 21:25
@AndyScherzinger
AndyScherzinger merged commit c726da5 into main Nov 21, 2026
52 checks passed
@AndyScherzinger
AndyScherzinger deleted the fix/scale-answer-plain-number branch November 21, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants