Skip to content

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

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

AndyScherzinger wants to merge 7 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

  • Editor: "Answer rules" in the question menu shows a rule row on the question card, as Google's "Response validation" and Microsoft's "Restrictions" do: each rule is a row of kind, condition and values with a remove button, and "Add rule" adds the next kind. Each kind can be used once per question, so rules combine (a length plus a required text), which a single rule row cannot express. Values that would make the rules impossible to meet are not saved; the reason shows below the field.
  • Long answer: Length (at least, at most or between a number of characters).
  • Short answer, input type Text: Length, "Must contain" and "Must not contain" (ignoring case, as Google's and Microsoft's contains / doesn't contain). 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 Number: Number (between, not between, greater than, at least, less than, at most, equal to, not equal to; decimals allowed) and "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, and rules that contradict each other: a required text containing the excluded text or longer than the maximum length, a range without a whole number while "Whole numbers only" is set). The API docs list these rejections.
  • 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, which rules cannot be combined, and 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).

Short and long answers share one AnswerRules component for the rule row. @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.

A separate commit fixes that a long answer kept its error message after the respondent corrected it, until the next submit (also on main); it now checks the answer again while typing, as short answers do.

Not covered (yet)

Screenshots

# Before After
Editor: short answer, Text Input type menu of a short answer without limits Question menu with Answer rules switched on, above the rule row of a short answer: length between 3 and 40, must contain GmbH, must not contain spam
Editor: short answer, Number Input type menu of a number answer without limits Rule row of a number answer, between 0 and 4
Editor: long answer Menu of a long answer without limits Rule row of a long answer, at most 200 characters
Editor: contradicting rules – Rule row refusing a required text longer than the maximum length of 3 characters
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 Rule row, 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 Rule row, 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 Rule row, 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 Rule row, 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 Rule row, 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 Rule row, 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 Rule row, 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

Mobile (390 px wide)

All views render without horizontal scrolling on a phone-sized screen; the rule row wraps onto several lines.

App Public link Embedded
All hints on a phone in the app All hints on a phone in the public link All hints on a phone in the embedded form
# Editor Error in the app Error in the public link Error in the embedded form
Number: between Rule row on a phone, between 0 and 4 Error on a phone in the app, between 0 and 4 Error on a phone in the public link, between 0 and 4 Error on a phone in the embedded form, between 0 and 4
Number: not between Rule row on a phone, not between 1 and 10 Error on a phone in the app, not between 1 and 10 Error on a phone in the public link, not between 1 and 10 Error on a phone in the embedded form, not between 1 and 10
Number: equal to Rule row on a phone, equal to 7 Error on a phone in the app, equal to 7 Error on a phone in the public link, equal to 7 Error on a phone in the embedded form, equal to 7
Number: not equal to Rule row on a phone, not equal to 13 Error on a phone in the app, not equal to 13 Error on a phone in the public link, not equal to 13 Error on a phone in the embedded form, not equal to 13
Number: greater than Rule row on a phone, greater than 0 Error on a phone in the app, greater than 0 Error on a phone in the public link, greater than 0 Error on a phone in the embedded form, greater than 0
Number: less than Rule row on a phone, less than 100 Error on a phone in the app, less than 100 Error on a phone in the public link, less than 100 Error on a phone in the embedded form, less than 100
Number: whole numbers only Rule row on a phone, whole numbers from 1 to 10 Error on a phone in the app, whole numbers from 1 to 10 Error on a phone in the public link, whole numbers from 1 to 10 Error on a phone in the embedded form, whole numbers from 1 to 10
Text: contains / does not contain Rule row on a phone, must contain GmbH and must not contain spam Error on a phone in the app, must contain GmbH and must not contain spam Error on a phone in the public link, must contain GmbH and must not contain spam Error on a phone in the embedded form, must contain GmbH and must not contain spam
URL Editor menu on a phone, URL input type Error on a phone in the app, URL input type Error on a phone in the public link, URL input type Error on a phone 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 each question's menu switch on "Answer rules", then add a length, each number condition, "Whole numbers only" and a text the answer must and must not contain; try a contradiction (a required text longer than the maximum length). Set the URL input type on another short answer in the input type menu.
  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 rule rows and the submit views, with hints and with errors; the question menu and the input type menu show errors from @nextcloud/vue that main has too.

🤖 AI (if applicable)

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

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…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>
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>
A long answer was checked only on submit. After a failed submit its
error, and aria-invalid, stayed while the respondent corrected the
text, and the hint stayed hidden until the next submit. Check the
answer again shortly after each change, as short answers already do.

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 0c5fe4a to 00bcbbf Compare November 27, 2026 13:51
@AndyScherzinger AndyScherzinger added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Nov 27, 2026
Google Forms ("Response validation") and Microsoft Forms
("Restrictions") show the rules of a question as a row of dropdowns
and values on the question card, switched on from the question menu.
The rules were hidden in the input type menu and the question menu so
far, so owners could not see them while editing and the number rule
needed a submenu.

"Answer rules" in the question menu now shows a rule row below the
answer field: one row per kind of rule with its condition and values,
"Add rule" and a remove button per rule. Each kind can be used once,
which keeps combinations like a length with a required text that a
single rule per question cannot express. Values that would make the rules
impossible to meet are not saved and are explained below the field.

Short and long answers share the new AnswerRules component instead of
duplicating the length fields.

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 00bcbbf to e9ffe37 Compare November 27, 2026 14:27
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