Skip to content

feat(questions): limit the length of text answers and the range of numbers - #4032

Draft
AndyScherzinger wants to merge 6 commits into
mainfrom
feat/answer-length-number-range
Draft

AndyScherzinger wants to merge 6 commits into
mainfrom
feat/answer-length-number-range

Conversation

@AndyScherzinger

@AndyScherzinger AndyScherzinger commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Ref #3076

Form owners can only restrict text answers through a custom regular expression today. That works for short answers only, is hard to write, and respondents never see the rule until they break it. Google Forms ("Response validation") and Microsoft Forms ("Restrictions") both let owners set character counts, number rules (between, not between, greater or less than, at least, at most, equal, not equal, whole numbers), texts an answer must or must not contain, and a URL check.

What changes

  • Long answer: "Require a minimum length" and "Limit the maximum length" in the question menu.
  • Short answer, input type Text: the same two length limits in the input type menu, next to the existing input types (Google offers length as one of its validation kinds, so it applies to plain text, not to email, phone or regex).
  • Short answer, input type Text: "Must contain" and "Must not contain" in the input type menu, ignoring case, as Google's and Microsoft's contains / doesn't contain.
  • Short answer, input type Number: a "Number rule" in the input type menu: any number, between, not between, greater than, at least, less than, at most, equal to, not equal to (decimals allowed), plus "Whole numbers only", as Google and Microsoft offer them. The browser gets min/max only for the rules that accept a range.
  • Short answer, new input type URL: accepts http and https addresses only.
  • Respondents see the rules as a hint above the field ("Enter between 3 and 12 characters", "Enter a number below 1 or above 10", "Include “GmbH” · Do not include “spam”"), a character counter below text fields ("11 / 40"), and the broken rule as error text; the hint is hidden while the error shows. The browser stops typing at the maximum length and uses the range on number inputs. Neither Google nor Microsoft shows a counter; it was asked for in Character limit for answers #3076.
  • Server rejects answers outside the limits and settings that do not fit together (length or required text on a validated short answer, a number rule without the Number type, not between without a number, whole numbers without the Number type, a minimum above its maximum, a length outside 1 to 4096, an empty required text).
  • API: new extraSettings lengthMin, lengthMax (short, long), numberMin, numberMax, numberExclude, numberInteger, textContains, textNotContains (short) and the validationType url, documented in docs/DataStructure.md; openapi.json regenerated. Equal to is stored as numberMin = numberMax, not between and not equal to add numberExclude: true; greater than and less than are numberExclude: true with only numberMax or numberMin, the one-sided form of not between.
  • Docs: new docs/AnswerRules.md for form owners: where to set each rule, what respondents see, and how changing the input type or number rule behaves, including the range proposed when switching to between (at most 50 → 0 to 50, at least 18 → 18 to 100, equal to 7 → 0 to 14).

@nextcloud/vue has no character counter; NcTextField/NcTextArea only offer a helperText, and the question fields are native inputs, so the counter and hint are built from the existing info and error note cards of the question.

Includes the fix of #4033 (a corrected short answer could not be submitted right away, also on main), which the end-to-end test needs; that commit drops out on rebase once #4033 is merged.

Not covered (yet)

Screenshots

# Before After
Editor: short answer, Text Input type menu of a short answer without limits Input type menu of a short answer with length limits and required texts
Editor: short answer, Number Input type menu of a number answer without limits Input type menu of a number answer with the number rule Between 0 and 4
Editor: long answer Menu of a long answer without limits Menu of a long answer with a maximum length of 200
Respondent: short answer, Text Short answer without hint Short answer with length hint and counter 5 / 12
Respondent: short answer, Number Number answer without hint Number answer with range hint
Respondent: long answer Long answer without hint Long answer with length hint and counter 29 / 200
Respondent: submitting "Al" and 6 guests Accepted and submitted Errors: Enter between 3 and 12 characters, Enter a number from 0 to 4

Further rules

The hint before answering and the error after submitting a breaking answer, in each view.

# Editor App Public link Embedded
Number: not between Editor menu, not between 1 and 10 Hint in the app, not between 1 and 10
Error in the app, not between 1 and 10
Hint in the public link, not between 1 and 10
Error in the public link, not between 1 and 10
Hint in the embedded form, not between 1 and 10
Error in the embedded form, not between 1 and 10
Number: equal to Editor menu, equal to 7 Hint in the app, equal to 7
Error in the app, equal to 7
Hint in the public link, equal to 7
Error in the public link, equal to 7
Hint in the embedded form, equal to 7
Error in the embedded form, equal to 7
Number: not equal to Editor menu, not equal to 13 Hint in the app, not equal to 13
Error in the app, not equal to 13
Hint in the public link, not equal to 13
Error in the public link, not equal to 13
Hint in the embedded form, not equal to 13
Error in the embedded form, not equal to 13
Number: greater than Editor menu, greater than 0 Hint in the app, greater than 0
Error in the app, greater than 0
Hint in the public link, greater than 0
Error in the public link, greater than 0
Hint in the embedded form, greater than 0
Error in the embedded form, greater than 0
Number: less than Editor menu, less than 100 Hint in the app, less than 100
Error in the app, less than 100
Hint in the public link, less than 100
Error in the public link, less than 100
Hint in the embedded form, less than 100
Error in the embedded form, less than 100
Number: whole numbers only Editor menu, whole numbers from 1 to 10 Hint in the app, whole numbers from 1 to 10
Error in the app, whole numbers from 1 to 10
Hint in the public link, whole numbers from 1 to 10
Error in the public link, whole numbers from 1 to 10
Hint in the embedded form, whole numbers from 1 to 10
Error in the embedded form, whole numbers from 1 to 10
Text: contains / does not contain Editor menu, must contain GmbH and must not contain spam Hint in the app, must contain GmbH and must not contain spam
Error in the app, must contain GmbH and must not contain spam
Hint in the public link, must contain GmbH and must not contain spam
Error in the public link, must contain GmbH and must not contain spam
Hint in the embedded form, must contain GmbH and must not contain spam
Error in the embedded form, must contain GmbH and must not contain spam
URL Editor menu, URL input type Hint in the app, URL input type
Error in the app, URL input type
Hint in the public link, URL input type
Error in the public link, URL input type
Hint in the embedded form, URL input type
Error in the embedded form, URL input type

How to test

  1. Create a form with a long answer, a short answer (Text) and a short answer (Number).
  2. In the menus, set a minimum and maximum length, each number rule, a text the answer must and must not contain, and the URL input type on another short answer.
  3. Open the form in the app, by public link and embedded: the hints and the counter show, typing stops at the maximum, an answer breaking a rule shows the error and blocks submitting.
  4. Send an answer breaking a rule through the API: the server rejects it.

playwright/e2e/answer-limits.spec.ts covers setting each rule in the editor, the hints, counter and errors in the app, by public link and embedded, the server rejecting each breaking answer (sent anonymously through a public share), and the server rejecting settings that do not fit together.

Checked on a live Nextcloud 35 in all three contexts, in light and dark theme; axe (WCAG 2.2 AA) reports no violations in the editor and the submit views, with hints and with errors.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (N/A)

…mbers

Form owners could only restrict text answers through a regular
expression, which only short answers offer and which respondents never
see. Google Forms and Microsoft Forms both let owners set a minimum and
maximum character count and a number range, so answers fit where they
are used later, for example in print.

Short and long answers now take a minimum and a maximum length, and
short answers validated as a number take a lowest and a highest number.
Respondents see the rule as a hint above the field, a character counter
below it, and the rule as error text when the answer breaks it. The
browser stops typing at the maximum length, and the server rejects
answers outside the limits.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.55072% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/Service/FormsService.php 97.22% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

A short answer kept its custom validity until the debounced check ran,
so submitting right after correcting an answer was silently blocked by
the browser. The answer now drops its custom validity as soon as it is
edited; submitting still validates every question.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Checks that owners can set a length limit, that respondents see the
hints and counters and cannot submit answers outside the limits, that
the server rejects them, and that a public link shows the limits.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Google Forms and Microsoft Forms offer more answer rules than a length
and a number range: a number must be equal to, not equal to or not
between given numbers, a text must or must not contain a word, and an
answer must be a web address.

Number answers now take one rule: any number, between, not between, at
least, at most, equal to or not equal to. It is stored as the lowest
and highest number plus numberExclude, so equal to is a range of one
number and not between rejects the range. Text answers take a text they
must contain and one they must not contain, ignoring case. The new URL
input type accepts http and https addresses only.

Respondents see each rule as a hint and the broken one as error text;
the server rejects answers breaking a rule and settings that do not fit
together. The Playwright spec covers the editor, the app, public links,
embedded forms and the API.

When the owner switches to a range rule, the editor proposes a range
from the current number: at most 50 becomes 0 to 50, at least 18
becomes 18 to 100 and equal to 7 becomes 0 to 14. The new
docs/AnswerRules.md explains the rules to form owners: where to set
them, what respondents see, and how changing the input type or the
number rule behaves, including these proposed ranges.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Google Forms and Microsoft Forms both offer strictly greater or less
than and whole numbers for number answers, so owners moving over expect
them.

Greater than and less than reuse numberExclude: excluding the range of
a single bound accepts only numbers above numberMax or below numberMin,
the one-sided form of "not between". A new numberInteger setting
accepts whole numbers only. The rules with one number share a single
"Number" field in the editor.

docs/AnswerRules.md covers the new rules, and that "Whole numbers only"
stays on when the owner changes the number rule.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
At most had no test at all and at least no end-to-end one; several
rules were only checked from one side. Add the missing valid answers at
the bounds, the missing illegal answers per rule, the single-bound and
equal settings, and set between, at least, at most and the text length
limits through the editor menus.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
@AndyScherzinger
AndyScherzinger force-pushed the feat/answer-length-number-range branch from 040bfbb to f463b7d Compare November 26, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant