From ee6a7b87e77db6c74fcc410117be31742e1223b0 Mon Sep 17 00:00:00 2001 From: global-prog Date: Wed, 9 Sep 2026 04:02:55 +0300 Subject: [PATCH 01/20] feat: rating question type Implements #356: a compact star rating, with hearts and thumbs as alternatives. A linear scale already covers 1..N, but as a row of radio buttons. A rating is the control people expect for "how would you rate this", takes far less width, and reads at a glance in the results. Built from real radio inputs rather than clickable icons, so it stays keyboard navigable and every option is announced with the value it selects. The hit area is a full clickable-area square while the icon itself stays small, since an icon-sized target is awkward to hit on a phone. The hover animation is dropped under prefers-reduced-motion. Configurable from 2 to 10 icons, defaulting to 5. The answer is stored as the plain number, so results and CSV export need no special handling. Validated server-side as a whole number within the configured maximum rather than trusting the client. Rating carries no options, so it is checked on its own rather than as a predefined-option type. No schema change. FormsQuestionType is left alone, matching how linearscale, ranking and color are already handled, so openapi.json is unaffected. Signed-off-by: global-prog --- lib/Constants.php | 11 + lib/Service/FormsService.php | 1 + lib/Service/SubmissionService.php | 13 + src/components/Questions/QuestionRating.vue | 272 ++++++++++++++++++++ src/models/AnswerTypes.ts | 12 + 5 files changed, 309 insertions(+) create mode 100644 src/components/Questions/QuestionRating.vue diff --git a/lib/Constants.php b/lib/Constants.php index 3e465cd0c..f541e6773 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -111,6 +111,7 @@ class Constants { public const ANSWER_TYPE_MULTIPLE = 'multiple'; public const ANSWER_TYPE_MULTIPLEUNIQUE = 'multiple_unique'; public const ANSWER_TYPE_RANKING = 'ranking'; + public const ANSWER_TYPE_RATING = 'rating'; public const ANSWER_TYPE_SHORT = 'short'; public const ANSWER_TYPE_TIME = 'time'; @@ -131,6 +132,7 @@ class Constants { self::ANSWER_TYPE_MULTIPLE, self::ANSWER_TYPE_MULTIPLEUNIQUE, self::ANSWER_TYPE_RANKING, + self::ANSWER_TYPE_RATING, self::ANSWER_TYPE_SHORT, self::ANSWER_TYPE_TIME, ]; @@ -229,6 +231,15 @@ class Constants { 'rows' => ['array'], ]; + /** + * How many icons a rating question offers, and which icon to draw. + * ratingIcon is one of 'star' (default), 'heart' or 'thumb'. + */ + public const EXTRA_SETTINGS_RATING = [ + 'maxRating' => ['integer', 'NULL'], + 'ratingIcon' => ['string', 'NULL'], + ]; + public const EXTRA_SETTINGS_RANKING = [ 'shuffleOptions' => ['boolean'], ]; diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index 197ababbc..818191b64 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -909,6 +909,7 @@ public function areExtraSettingsValid(array $extraSettings, string $questionType Constants::ANSWER_TYPE_DATE => Constants::EXTRA_SETTINGS_DATE, Constants::ANSWER_TYPE_GRID => Constants::EXTRA_SETTINGS_GRID, Constants::ANSWER_TYPE_RANKING => Constants::EXTRA_SETTINGS_RANKING, + Constants::ANSWER_TYPE_RATING => Constants::EXTRA_SETTINGS_RATING, Constants::ANSWER_TYPE_TIME => Constants::EXTRA_SETTINGS_TIME, Constants::ANSWER_TYPE_LINEARSCALE => Constants::EXTRA_SETTINGS_LINEARSCALE, default => [], diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index 0678b7ad8..1d070c458 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -699,6 +699,19 @@ public function validateSubmission(array $questions, array $answers, string $for } // Check if all answers are within the possible options + // A rating carries no options, so it is validated on its own rather than as a + // predefined-option type: the answer is the number of icons chosen. + if ($question['type'] === Constants::ANSWER_TYPE_RATING) { + $maxRating = $question['extraSettings']['maxRating'] ?? 5; + foreach ($answers[$questionId] as $answer) { + if (!ctype_digit((string)$answer) + || (int)$answer < 1 + || (int)$answer > $maxRating) { + throw new \InvalidArgumentException(sprintf('The answer for question "%s" must be a whole number between 1 and %d.', $question['text'], $maxRating)); + } + } + } + if (in_array($question['type'], Constants::ANSWER_TYPES_PREDEFINED)) { // Normalize option IDs once for consistent comparison (DB may return ints, request may send strings) $optionIds = $this->normalizeOptionIds($question['options'] ?? []); diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue new file mode 100644 index 000000000..49d5b5286 --- /dev/null +++ b/src/components/Questions/QuestionRating.vue @@ -0,0 +1,272 @@ + + + + + + + diff --git a/src/models/AnswerTypes.ts b/src/models/AnswerTypes.ts index e2bc47b9e..6beab4bb8 100644 --- a/src/models/AnswerTypes.ts +++ b/src/models/AnswerTypes.ts @@ -17,6 +17,7 @@ import IconPalette from '@material-symbols/svg-400/outlined/palette.svg?raw' import IconRadioboxMarked from '@material-symbols/svg-400/outlined/radio_button_checked.svg?raw' import IconClockOutline from '@material-symbols/svg-400/outlined/schedule.svg?raw' import IconTextShort from '@material-symbols/svg-400/outlined/short_text.svg?raw' +import IconStar from '@material-symbols/svg-400/outlined/star.svg?raw' import IconTextLong from '@material-symbols/svg-400/outlined/subject.svg?raw' import IconSwapVertical from '@material-symbols/svg-400/outlined/swap_vert.svg?raw' import { t } from '@nextcloud/l10n' @@ -30,6 +31,7 @@ import QuestionLinearScale from '../components/Questions/QuestionLinearScale.vue import QuestionLong from '../components/Questions/QuestionLong.vue' import QuestionMultiple from '../components/Questions/QuestionMultiple.vue' import QuestionRanking from '../components/Questions/QuestionRanking.vue' +import QuestionRating from '../components/Questions/QuestionRating.vue' import QuestionShort from '../components/Questions/QuestionShort.vue' import { OptionType } from './Constants.ts' @@ -267,6 +269,16 @@ const answerTypes: Record = { warningInvalid: t('forms', 'This question needs a title!'), }, + rating: { + component: markRaw(QuestionRating), + icon: IconStar, + label: t('forms', 'Rating'), + predefined: false, + + titlePlaceholder: t('forms', 'Rating question title'), + warningInvalid: t('forms', 'This question needs a title!'), + }, + color: { component: markRaw(QuestionColor), icon: IconPalette, From 5074020662d43340ed78d2b0bcaa77c339482366 Mon Sep 17 00:00:00 2001 From: global-prog Date: Fri, 11 Sep 2026 17:30:52 +0300 Subject: [PATCH 02/20] refactor: build the rating on the linear scale's settings and validation A rating is a linear scale that always starts at 1 and is drawn as icons, so it should not carry settings and checks of its own: * its top end is stored as optionsHighest rather than a separate maxRating key, and optionsLowest is refused, since a rating's lowest end is always 1; * the linear scale's bounds on optionsHighest (2 to 10) now apply to it as well. The editor already offered exactly that range, but the server never enforced it; * the range check that validated linear scale answers is moved into one helper that both types call, keeping its message and defaults, so linear scale behaviour is unchanged. Adds tests for the rating's accepted settings and for its answer validation, which the first commit did not have. Signed-off-by: global-prog --- lib/Constants.php | 8 ++- lib/Service/FormsService.php | 6 +- lib/Service/SubmissionService.php | 37 ++++++---- src/components/Questions/QuestionRating.vue | 26 +++---- tests/Unit/Service/FormsServiceTest.php | 30 ++++++++ tests/Unit/Service/SubmissionServiceTest.php | 72 ++++++++++++++++++++ 6 files changed, 148 insertions(+), 31 deletions(-) diff --git a/lib/Constants.php b/lib/Constants.php index f541e6773..42130d4b4 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -232,11 +232,13 @@ class Constants { ]; /** - * How many icons a rating question offers, and which icon to draw. - * ratingIcon is one of 'star' (default), 'heart' or 'thumb'. + * A rating is a linear scale that always starts at 1 and is drawn as icons, so it + * shares the linear scale's key for its top end (and that key's bounds) rather than + * having one of its own. optionsLowest is deliberately absent: a rating's lowest end + * is always 1. ratingIcon is one of 'star' (default), 'heart' or 'thumb'. */ public const EXTRA_SETTINGS_RATING = [ - 'maxRating' => ['integer', 'NULL'], + 'optionsHighest' => ['integer', 'NULL'], 'ratingIcon' => ['string', 'NULL'], ]; diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index 818191b64..456268778 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -1046,8 +1046,10 @@ public function areExtraSettingsValid(array $extraSettings, string $questionType } // Special handling of linear scale validation - } elseif ($questionType === Constants::ANSWER_TYPE_LINEARSCALE) { - // Ensure limits are sane + } elseif ($questionType === Constants::ANSWER_TYPE_LINEARSCALE + || $questionType === Constants::ANSWER_TYPE_RATING) { + // Ensure limits are sane. A rating cannot set optionsLowest at all, so for it + // only the top end is checked. if (isset($extraSettings['optionsLowest']) && ($extraSettings['optionsLowest'] < 0 || $extraSettings['optionsLowest'] > 1) || isset($extraSettings['optionsHighest']) && ($extraSettings['optionsHighest'] < 2 || $extraSettings['optionsHighest'] > 10)) { return false; diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index 1d070c458..3f17a3666 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -699,16 +699,12 @@ public function validateSubmission(array $questions, array $answers, string $for } // Check if all answers are within the possible options - // A rating carries no options, so it is validated on its own rather than as a - // predefined-option type: the answer is the number of icons chosen. + // A rating carries no options, so it cannot go through the predefined-option + // branch below, but its answer is a point on a scale exactly as a linear scale's + // is, so it is held to the same rule. if ($question['type'] === Constants::ANSWER_TYPE_RATING) { - $maxRating = $question['extraSettings']['maxRating'] ?? 5; foreach ($answers[$questionId] as $answer) { - if (!ctype_digit((string)$answer) - || (int)$answer < 1 - || (int)$answer > $maxRating) { - throw new \InvalidArgumentException(sprintf('The answer for question "%s" must be a whole number between 1 and %d.', $question['text'], $maxRating)); - } + $this->validateScaleAnswer($question, $answer); } } @@ -719,11 +715,7 @@ public function validateSubmission(array $questions, array $answers, string $for foreach ($answers[$questionId] as $answer) { // Handle linear scale questions if ($question['type'] === Constants::ANSWER_TYPE_LINEARSCALE) { - $optionsLowest = $question['extraSettings']['optionsLowest'] ?? 1; - $optionsHighest = $question['extraSettings']['optionsHighest'] ?? 5; - if (!is_scalar($answer) || is_bool($answer) || !ctype_digit((string)$answer) || intval($answer) < $optionsLowest || intval($answer) > $optionsHighest) { - throw new \InvalidArgumentException(sprintf('The answer for question "%s" must be an integer between %d and %d.', $question['text'], $optionsLowest, $optionsHighest)); - } + $this->validateScaleAnswer($question, $answer); } // Check if all grid rows, columns and values match the configured grid subtype elseif ($question['type'] === Constants::ANSWER_TYPE_GRID) { @@ -804,6 +796,25 @@ public function validateSubmission(array $questions, array $answers, string $for } } + /** + * Check one answer to a question answered on a numbered scale. + * + * Shared by the linear scale and the rating, which differ only in how the scale is + * drawn. The bounds and their defaults are the linear scale's; a rating does not + * accept optionsLowest, so its lowest end always falls back to 1. + * + * @param array $question the question being answered + * @param mixed $answer one submitted value + * @throws \InvalidArgumentException if the answer is not a whole number within range + */ + private function validateScaleAnswer(array $question, mixed $answer): void { + $optionsLowest = $question['extraSettings']['optionsLowest'] ?? 1; + $optionsHighest = $question['extraSettings']['optionsHighest'] ?? 5; + if (!ctype_digit((string)$answer) || intval($answer) < $optionsLowest || intval($answer) > $optionsHighest) { + throw new \InvalidArgumentException(sprintf('The answer for question "%s" must be an integer between %d and %d.', $question['text'], $optionsLowest, $optionsHighest)); + } + } + /** * Validate correct date/time formats * @param array $answers Array with date from answer diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue index 49d5b5286..89edb9a45 100644 --- a/src/components/Questions/QuestionRating.vue +++ b/src/components/Questions/QuestionRating.vue @@ -12,14 +12,14 @@ v-on="commonListeners"> -
+
{{ text || t('forms', 'Rating') }} @@ -49,7 +52,7 @@ type="radio" :name="`rating_${id}`" :aria-label=" - n('forms', '%n of {max}', '%n of {max}', value, { + t('forms', '%n of {max}', { max: optionsHighest, }) " @@ -58,14 +61,12 @@ :required="isRequired && !currentValue" @change="onPick(value)" /> + :svg=" + value <= currentValue + ? currentIconChoice.filled + : currentIconChoice.outline + " /> - - {{ t('forms', 'Clear') }} -
@@ -77,11 +78,10 @@ import IconStarFilled from '@material-symbols/svg-400/outlined/star-fill.svg?raw import IconStar from '@material-symbols/svg-400/outlined/star.svg?raw' import IconThumbFilled from '@material-symbols/svg-400/outlined/thumb_up-fill.svg?raw' import IconThumb from '@material-symbols/svg-400/outlined/thumb_up.svg?raw' -import { n, t } from '@nextcloud/l10n' +import { t } from '@nextcloud/l10n' import { computed, defineComponent } from 'vue' import NcActionInput from '@nextcloud/vue/components/NcActionInput' import NcActionRadio from '@nextcloud/vue/components/NcActionRadio' -import NcButton from '@nextcloud/vue/components/NcButton' import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper' import Question from './Question.vue' import { @@ -90,16 +90,49 @@ import { useQuestion, } from '../../composables/useQuestion.ts' -/** Matches the linear scale default the server assumes when optionsHighest is unset. */ const DEFAULT_OPTIONS_HIGHEST = 5 +interface IconChoice { + id: 'star' | 'heart' | 'thumb' + label: string + outline: string + filled: string + color: string +} + +const ICON_CHOICES: IconChoice[] = [ + { + id: 'star', + label: t('forms', 'Stars'), + outline: IconStar, + filled: IconStarFilled, + color: 'var(--color-element-warning)', + }, + { + id: 'heart', + label: t('forms', 'Hearts'), + outline: IconHeart, + filled: IconHeartFilled, + color: 'var(--color-element-error)', + }, + { + id: 'thumb', + label: t('forms', 'Thumbs up'), + outline: IconThumb, + filled: IconThumbFilled, + color: 'var(--color-element-info)', + }, +] + +const VALID_ICONS = ICON_CHOICES.map((choice) => choice.id) +const DEFAULT_ICON = ICON_CHOICES[0].id + export default defineComponent({ name: 'QuestionRating', components: { NcActionInput, NcActionRadio, - NcButton, NcIconSvgWrapper, Question, }, @@ -125,32 +158,13 @@ export default defineComponent({ const ratingIcon = computed(() => { const icon = extraSettings.value.ratingIcon - return typeof icon === 'string' - && ['star', 'heart', 'thumb'].includes(icon) + return typeof icon === 'string' && VALID_ICONS.includes(icon as never) ? icon - : 'star' + : DEFAULT_ICON }) - const iconChoices = computed(() => [ - { id: 'star', label: t('forms', 'Stars') }, - { id: 'heart', label: t('forms', 'Hearts') }, - { id: 'thumb', label: t('forms', 'Thumbs up') }, - ]) - - const outlineIcon = computed( - () => - ({ star: IconStar, heart: IconHeart, thumb: IconThumb })[ - ratingIcon.value - ], - ) - - const filledIcon = computed( - () => - ({ - star: IconStarFilled, - heart: IconHeartFilled, - thumb: IconThumbFilled, - })[ratingIcon.value], + const currentIconChoice = computed(() => + ICON_CHOICES.find((choice) => choice.id === ratingIcon.value)!, ) const currentValue = computed( @@ -179,7 +193,7 @@ export default defineComponent({ */ function onRatingIconChange(icon: string): void { question.onExtraSettingsChange({ - ratingIcon: icon === 'star' ? null : icon, + ratingIcon: icon === DEFAULT_ICON ? null : icon, }) } @@ -201,15 +215,13 @@ export default defineComponent({ return { ...question, + currentIconChoice, currentValue, - filledIcon, - iconChoices, + iconChoices: ICON_CHOICES, optionsHighest, - n, onOptionsHighestChange, onPick, onRatingIconChange, - outlineIcon, ratingIcon, t, validate, @@ -243,10 +255,6 @@ export default defineComponent({ color 0.1s ease-in-out, transform 0.1s ease-in-out; - &--on { - color: var(--color-favorite, var(--color-warning)); - } - &:hover { transform: scale(1.1); } @@ -256,6 +264,10 @@ export default defineComponent({ outline-offset: -2px; } + &--on { + color: var(--rating-color); + } + @media (prefers-reduced-motion: reduce) { transition: none; diff --git a/src/components/Results/ResultsSummary.vue b/src/components/Results/ResultsSummary.vue index 4156ba3ef..8228d9902 100644 --- a/src/components/Results/ResultsSummary.vue +++ b/src/components/Results/ResultsSummary.vue @@ -247,7 +247,10 @@ export default defineComponent({ const questionOptions = computed(() => { // Build list of question options let questionOptionsStats: OptionStats[] - if (props.question.type !== 'linearscale') { + if ( + props.question.type !== 'linearscale' + && props.question.type !== 'rating' + ) { questionOptionsStats = (props.question.options ?? []).map( (option) => ({ ...option, @@ -342,7 +345,10 @@ export default defineComponent({ }) // Sort options by response count - if (props.question.type !== 'linearscale') { + if ( + props.question.type !== 'linearscale' + && props.question.type !== 'rating' + ) { questionOptionsStats.sort( (object1, object2) => object2.count - object1.count, ) diff --git a/src/models/AnswerTypes.ts b/src/models/AnswerTypes.ts index 6beab4bb8..d5103d5c3 100644 --- a/src/models/AnswerTypes.ts +++ b/src/models/AnswerTypes.ts @@ -273,7 +273,7 @@ const answerTypes: Record = { component: markRaw(QuestionRating), icon: IconStar, label: t('forms', 'Rating'), - predefined: false, + predefined: true, titlePlaceholder: t('forms', 'Rating question title'), warningInvalid: t('forms', 'This question needs a title!'), From b7593987eb9b8ea81fa3ca2156ea9ca1bc1c338c Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:05:22 +0100 Subject: [PATCH 04/20] fix(rating): check rating answers against the scale, not ranking answers The list of question types answered on a scale named the ranking instead of the rating. A ranking answer is a list of option ids, so a ranking whose option ids are above the scale's top was rejected, while a rating answer was not checked at all. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- lib/Constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Constants.php b/lib/Constants.php index 4db4e54a3..467fb4607 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -157,7 +157,7 @@ class Constants { // AnswerTypes for scale questions // TODO: add linearscale public const ANSWER_TYPES_SCALE = [ - self::ANSWER_TYPE_RANKING, + self::ANSWER_TYPE_RATING, ]; // Formats for AnswerTypes date/datetime/time From ac8fdb676e3416864055fe05da5251a86617a3d9 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:05:29 +0100 Subject: [PATCH 05/20] fix(rating): reject booleans and lists as answers on a scale Moving the check of linear scale answers into validateScaleQuestion left out the check that an answer is a single value and not a boolean, so true was accepted as the answer 1 again. The shared check now has it back, for linear scales and ratings alike. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- lib/Service/SubmissionService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index e102e3fc1..9ba000652 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -809,7 +809,7 @@ public function validateSubmission(array $questions, array $answers, string $for private function validateScaleQuestion(array $question, mixed $answer): void { $optionsLowest = $question['extraSettings']['optionsLowest'] ?? 1; $optionsHighest = $question['extraSettings']['optionsHighest'] ?? 5; - if (!ctype_digit((string)$answer) || intval($answer) < $optionsLowest || intval($answer) > $optionsHighest) { + if (!is_scalar($answer) || is_bool($answer) || !ctype_digit((string)$answer) || intval($answer) < $optionsLowest || intval($answer) > $optionsHighest) { throw new \InvalidArgumentException(sprintf('The answer for question "%s" must be an integer between %d and %d.', $question['text'], $optionsLowest, $optionsHighest)); } } From 8daab99c5cb91eaca3f8ce78edbe716e7bd2928c Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:27:36 +0100 Subject: [PATCH 06/20] fix(rating): name each option of a rating by its value Every option of a rating was announced as "undefined of 5": t() fills in %n only when it is given a count, and the label passed none. Each option is now named by its own value, e.g. "3 of 5". Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- src/components/Questions/QuestionRating.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue index 17342ee1d..2bdf7e6a6 100644 --- a/src/components/Questions/QuestionRating.vue +++ b/src/components/Questions/QuestionRating.vue @@ -47,12 +47,14 @@ :key="value" class="rating__icon" :class="{ 'rating__icon--on': value <= currentValue }"> + Date: Thu, 19 Nov 2026 11:27:53 +0100 Subject: [PATCH 07/20] fix(rating): keep the rating in view when one of its options gets focus The radios of a rating used the server's hidden-visually class, which moves them 10000px above and beside the question. Clicking an icon or tabbing to it focuses that radio, so the browser scrolled the form to its top and the rating left the screen. The radios now stay in place inside their icon, invisible and ignoring the pointer, the same way NcRadioGroupButton hides its own. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- src/components/Questions/QuestionRating.vue | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue index 2bdf7e6a6..37ddcec3e 100644 --- a/src/components/Questions/QuestionRating.vue +++ b/src/components/Questions/QuestionRating.vue @@ -49,7 +49,7 @@ :class="{ 'rating__icon--on': value <= currentValue }"> Date: Thu, 19 Nov 2026 11:29:09 +0100 Subject: [PATCH 09/20] fix(rating): focus a new rating question and keep its insert menu The editor focuses the title of a question once it is added, copied or inserted, and offers a menu below each question to insert another one after it. A rating did neither: it gave the shared question code no root element to scroll to and focus, so focus was lost, and it did not pass on the insert slot, so the menu below it was missing. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- src/components/Questions/QuestionRating.vue | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue index 37ddcec3e..12999cd4f 100644 --- a/src/components/Questions/QuestionRating.vue +++ b/src/components/Questions/QuestionRating.vue @@ -5,6 +5,7 @@ @@ -81,7 +85,7 @@ import IconStar from '@material-symbols/svg-400/outlined/star.svg?raw' import IconThumbFilled from '@material-symbols/svg-400/outlined/thumb_up-fill.svg?raw' import IconThumb from '@material-symbols/svg-400/outlined/thumb_up.svg?raw' import { t } from '@nextcloud/l10n' -import { computed, defineComponent } from 'vue' +import { computed, defineComponent, ref } from 'vue' import NcActionInput from '@nextcloud/vue/components/NcActionInput' import NcActionRadio from '@nextcloud/vue/components/NcActionRadio' import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper' @@ -143,7 +147,8 @@ export default defineComponent({ emits: [...QUESTION_EMITS, 'update:values'], setup(props, { emit }) { - const question = useQuestion(props, { emit }) + const rootElement = ref<{ $el?: HTMLElement } | null>(null) + const question = useQuestion(props, { emit, rootElement }) const extraSettings = computed( () => (props.extraSettings as Record | undefined) ?? {}, @@ -225,6 +230,7 @@ export default defineComponent({ onPick, onRatingIconChange, ratingIcon, + rootElement, t, validate, } From 94f1a0e9a8927f30016aadc8c8fc60522b561808 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:29:28 +0100 Subject: [PATCH 10/20] fix(rating): show why a required rating cannot be submitted A required rating left empty failed the browser's own validation, which stops the submit before Forms checks the answers. Its message was tied to a radio placed off screen, and the rating's error note never showed. The rating now handles the invalid event like the other questions, so it shows "You must answer this question" and marks its radios invalid, pointing to that note. The radios also stay required once one is picked, so screen readers keep announcing the question as required, and the rating is described by the question's description. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- src/components/Questions/QuestionRating.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue index 12999cd4f..f6749645b 100644 --- a/src/components/Questions/QuestionRating.vue +++ b/src/components/Questions/QuestionRating.vue @@ -39,6 +39,7 @@
{{ text || t('forms', 'Rating') }} @@ -59,10 +60,13 @@ max: optionsHighest, }) " + :aria-errormessage="hasError ? errorId : undefined" + :aria-invalid="hasError ? 'true' : undefined" :value="value" :checked="value === currentValue" - :required="isRequired && !currentValue" - @change="onPick(value)" /> + :required="isRequired" + @change="onPick(value)" + @invalid.prevent="validate" /> + @invalid.prevent="validate" + @keydown.enter.exact.prevent="onKeydownEnter" /> Date: Thu, 19 Nov 2026 11:30:18 +0100 Subject: [PATCH 13/20] refactor(rating): drop the clear-button leftovers and a second icon lookup The clear button is gone, so a rating is only ever picked with a value from 1 up: onPick no longer handles 0, and the comments that still mentioned clearing are removed. The chosen icon set was checked against a list derived from the icon choices and then looked up in those choices again. It is now looked up once, with stars as the fallback, which also drops a cast and a non-null assertion. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- src/components/Questions/QuestionRating.vue | 27 ++++++++------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue index 32a4a5f24..4204ec4c6 100644 --- a/src/components/Questions/QuestionRating.vue +++ b/src/components/Questions/QuestionRating.vue @@ -29,7 +29,7 @@ @@ -136,8 +136,7 @@ const ICON_CHOICES: IconChoice[] = [ }, ] -const VALID_ICONS = ICON_CHOICES.map((choice) => choice.id) -const DEFAULT_ICON = ICON_CHOICES[0].id +const DEFAULT_ICON_CHOICE = ICON_CHOICES[0] export default defineComponent({ name: 'QuestionRating', @@ -169,15 +168,11 @@ export default defineComponent({ : DEFAULT_OPTIONS_HIGHEST }) - const ratingIcon = computed(() => { - const icon = extraSettings.value.ratingIcon - return typeof icon === 'string' && VALID_ICONS.includes(icon as never) - ? icon - : DEFAULT_ICON - }) - - const currentIconChoice = computed(() => - ICON_CHOICES.find((choice) => choice.id === ratingIcon.value)!, + const currentIconChoice = computed( + () => + ICON_CHOICES.find( + (choice) => choice.id === extraSettings.value.ratingIcon, + ) ?? DEFAULT_ICON_CHOICE, ) const currentValue = computed( @@ -185,10 +180,10 @@ export default defineComponent({ ) /** - * @param value the chosen count, or 0 to clear the answer + * @param value the chosen rating */ function onPick(value: number): void { - emit('update:values', value ? [String(value)] : []) + emit('update:values', [String(value)]) question.errorMessage.value = null } @@ -206,7 +201,7 @@ export default defineComponent({ */ function onRatingIconChange(icon: string): void { question.onExtraSettingsChange({ - ratingIcon: icon === DEFAULT_ICON ? null : icon, + ratingIcon: icon === DEFAULT_ICON_CHOICE.id ? null : icon, }) } @@ -235,7 +230,6 @@ export default defineComponent({ onOptionsHighestChange, onPick, onRatingIconChange, - ratingIcon, rootElement, t, validate, @@ -249,7 +243,6 @@ export default defineComponent({ align-items: center; border: none; display: flex; - // Ten icons plus a Clear button do not fit one line on a narrow screen. flex-wrap: wrap; gap: 2px; margin: 0; From 482e8f63e215da96020195929680d98dc75733d6 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:33:50 +0100 Subject: [PATCH 14/20] style: format the list of date and time answer types Moving ANSWER_TYPES_DATETIME left a line holding only a tab and indented its entries one tab too deep, which the PHP coding standard rejects. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- lib/Constants.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Constants.php b/lib/Constants.php index 467fb4607..96120b4da 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -136,12 +136,12 @@ class Constants { self::ANSWER_TYPE_SHORT, self::ANSWER_TYPE_TIME, ]; - + // AnswerTypes for date/time questions public const ANSWER_TYPES_DATETIME = [ - self::ANSWER_TYPE_DATE, - self::ANSWER_TYPE_DATETIME, - self::ANSWER_TYPE_TIME, + self::ANSWER_TYPE_DATE, + self::ANSWER_TYPE_DATETIME, + self::ANSWER_TYPE_TIME, ]; // AnswerTypes, that need/have predefined Options From 3658d8d8c8b182974b269346f9d8e270fb6f7ca5 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:34:14 +0100 Subject: [PATCH 15/20] fix(rating): reject answers on a scale written with leading zeros An answer such as "05" passed the check of scale answers and was stored as sent. The results then counted it as a value of its own next to 5, and exports showed it as written. Answers to a linear scale or a rating now have to be the plain number. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- lib/Service/SubmissionService.php | 4 ++-- tests/Unit/Service/SubmissionServiceTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Service/SubmissionService.php b/lib/Service/SubmissionService.php index 9ba000652..f635e6d98 100644 --- a/lib/Service/SubmissionService.php +++ b/lib/Service/SubmissionService.php @@ -804,12 +804,12 @@ public function validateSubmission(array $questions, array $answers, string $for * * @param array $question the question being answered * @param mixed $answer one submitted value - * @throws \InvalidArgumentException if the answer is not a whole number within range + * @throws \InvalidArgumentException if the answer is not a whole number within range, written without leading zeros */ private function validateScaleQuestion(array $question, mixed $answer): void { $optionsLowest = $question['extraSettings']['optionsLowest'] ?? 1; $optionsHighest = $question['extraSettings']['optionsHighest'] ?? 5; - if (!is_scalar($answer) || is_bool($answer) || !ctype_digit((string)$answer) || intval($answer) < $optionsLowest || intval($answer) > $optionsHighest) { + if (!is_scalar($answer) || is_bool($answer) || !ctype_digit((string)$answer) || (string)intval($answer) !== (string)$answer || intval($answer) < $optionsLowest || intval($answer) > $optionsHighest) { throw new \InvalidArgumentException(sprintf('The answer for question "%s" must be an integer between %d and %d.', $question['text'], $optionsLowest, $optionsHighest)); } } diff --git a/tests/Unit/Service/SubmissionServiceTest.php b/tests/Unit/Service/SubmissionServiceTest.php index 20eb5daba..1d44c066f 100644 --- a/tests/Unit/Service/SubmissionServiceTest.php +++ b/tests/Unit/Service/SubmissionServiceTest.php @@ -1044,6 +1044,18 @@ public static function dataValidateSubmission() { // Expected Result 'The answer for question "r" must be an integer between 1 and 5.', ], + 'rating-leading-zero' => [ + // Questions + [ + ['id' => 1, 'type' => 'rating', 'text' => 'r', 'isRequired' => false], + ], + // Answers + [ + '1' => ['05'], + ], + // Expected Result + 'The answer for question "r" must be an integer between 1 and 5.', + ], 'required-not-answered' => [ // Questions [ From a7d3d4fc2ce6531b0757c7b3c20ba25a79305325 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:35:02 +0100 Subject: [PATCH 16/20] fix(rating): accept only the icons a rating can draw The server took any text as the icon of a rating, while the editor only offers stars, hearts and thumbs up and draws stars for anything else, so an API client could store an icon that no one ever sees. The icon is now checked against the three choices, and the API description lists them. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- lib/Constants.php | 7 +++++++ lib/ResponseDefinitions.php | 1 + lib/Service/FormsService.php | 3 ++- openapi.json | 8 ++++++++ tests/Unit/Service/FormsServiceTest.php | 7 +++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/Constants.php b/lib/Constants.php index 96120b4da..2e00287a9 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -242,6 +242,13 @@ class Constants { 'ratingIcon' => ['string', 'NULL'], ]; + // should be in sync with ICON_CHOICES in QuestionRating.vue + public const EXTRA_SETTINGS_RATING_ICONS = [ + 'star', + 'heart', + 'thumb', + ]; + public const EXTRA_SETTINGS_RANKING = [ 'shuffleOptions' => ['boolean'], ]; diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 15ed97324..d662de78d 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -35,6 +35,7 @@ * optionsLimitMax?: int, * optionsLimitMin?: int, * optionsLowest?: 0|1, + * ratingIcon?: "star"|"heart"|"thumb", * shuffleOptions?: bool, * timeMax?: string, * timeMin?: string, diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index 456268778..b8f8f5783 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -1051,7 +1051,8 @@ public function areExtraSettingsValid(array $extraSettings, string $questionType // Ensure limits are sane. A rating cannot set optionsLowest at all, so for it // only the top end is checked. if (isset($extraSettings['optionsLowest']) && ($extraSettings['optionsLowest'] < 0 || $extraSettings['optionsLowest'] > 1) - || isset($extraSettings['optionsHighest']) && ($extraSettings['optionsHighest'] < 2 || $extraSettings['optionsHighest'] > 10)) { + || isset($extraSettings['optionsHighest']) && ($extraSettings['optionsHighest'] < 2 || $extraSettings['optionsHighest'] > 10) + || isset($extraSettings['ratingIcon']) && !in_array($extraSettings['ratingIcon'], Constants::EXTRA_SETTINGS_RATING_ICONS, true)) { return false; } } diff --git a/openapi.json b/openapi.json index 4336a8c92..8be94e556 100644 --- a/openapi.json +++ b/openapi.json @@ -575,6 +575,14 @@ 1 ] }, + "ratingIcon": { + "type": "string", + "enum": [ + "star", + "heart", + "thumb" + ] + }, "shuffleOptions": { "type": "boolean" }, diff --git a/tests/Unit/Service/FormsServiceTest.php b/tests/Unit/Service/FormsServiceTest.php index 20d67844c..fe3469d2f 100644 --- a/tests/Unit/Service/FormsServiceTest.php +++ b/tests/Unit/Service/FormsServiceTest.php @@ -1670,6 +1670,13 @@ public static function dataAreExtraSettingsValid() { 'questionType' => Constants::ANSWER_TYPE_RATING, 'expected' => true ], + 'rating-unknown-icon' => [ + 'extraSettings' => [ + 'ratingIcon' => 'smiley', + ], + 'questionType' => Constants::ANSWER_TYPE_RATING, + 'expected' => false + ], 'rating-top-above-scale-limit' => [ 'extraSettings' => [ 'optionsHighest' => 11, From bf8998d6b3bda8b52cac0271b4f02b4579c4b06c Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:35:34 +0100 Subject: [PATCH 17/20] docs: describe the rating question and its settings The API documentation listed neither the rating question type nor its icon setting, and showed the highest value of a scale as a setting of the linear scale only. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- docs/DataStructure.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/DataStructure.md b/docs/DataStructure.md index d0e9acfa3..a358456e0 100644 --- a/docs/DataStructure.md +++ b/docs/DataStructure.md @@ -238,6 +238,7 @@ Currently supported Question-Types are: | `time` | Showing a dropdown menu to select a time. | | `file` | One or multiple files. It is possible to specify which mime types are allowed | | `linearscale` | A linear or Likert scale question where you choose an option that best fits your opinion | +| `rating` | A rating from 1 to the highest value, shown as stars, hearts or thumbs up. The answer is the number of the chosen icon. | | `color` | A color answer, hex string representation (e. g. `#123456`) | | `ranking` | Using pre-defined options, the user ranks them from most to least preferred. Needs at least one option available. Answers are stored in ranked order (one answer row per option). | @@ -264,9 +265,10 @@ Optional extra settings for some [Question Types](#question-types) | `timeMin` | `time` | string | - | Minimum allowed time to be chosen (as `HH:mm` string) | | `timeRange` | `time` | Boolean | `true/false` | The time picker should query a time range | | `optionsLowest` | `linearscale` | Integer | `0, 1` | Set the lowest value of the scale, default: `1` | -| `optionsHighest` | `linearscale` | Integer | `2, 3, 4, 5, 6, 7, 8, 9, 10` | Set the highest value of the scale, default: `5` | +| `optionsHighest` | `linearscale, rating` | Integer | `2, 3, 4, 5, 6, 7, 8, 9, 10` | Set the highest value of the scale, default: `5` | | `optionsLabelLowest` | `linearscale` | string | - | Set the label of the lowest value, default: `'Strongly disagree'` | | `optionsLabelHighest` | `linearscale` | string | - | Set the label of the highest value, default: `'Strongly agree'` | +| `ratingIcon` | `rating` | string | `'star', 'heart', 'thumb'` | Set the icon of the rating, default: `'star'` | | `columns` | `grid` | Array | - | Array of column identifiers / labels for grid questions | | `rows` | `grid` | Array | - | Array of row identifiers / labels for grid questions | | `questionType` | `grid` | String | `checkbox`, `number`, `radio` | Type of cell for grid questions (checkbox, numeric input, or radio) | From 16d609106ec34c6313b2ec2798ee74def266e877 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 19 Nov 2026 11:40:31 +0100 Subject: [PATCH 18/20] refactor(rating): name the rating by the question title The rating repeated its question title in a hidden legend. Like every other question, it now points to the title itself, which also announces the asterisk of a required question. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- src/components/Questions/QuestionRating.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Questions/QuestionRating.vue b/src/components/Questions/QuestionRating.vue index 4204ec4c6..e491d1323 100644 --- a/src/components/Questions/QuestionRating.vue +++ b/src/components/Questions/QuestionRating.vue @@ -40,11 +40,9 @@
- - {{ text || t('forms', 'Rating') }} -