This commit is contained in:
2026-08-20 18:29:27 +05:00
parent 010f78b138
commit 51339b3f9a
8 changed files with 177 additions and 83 deletions
+17 -7
View File
@@ -1,4 +1,4 @@
import type { FeedbackErrors, IFeedbackData } from './model';
import { getVisibleAppealFields, type FeedbackErrors, type IFeedbackData } from './model';
import { TEXTS } from './texts';
/** Ниже этой длины текст не считаем содержательным описанием. */
@@ -26,14 +26,24 @@ export function validateFeedback(data: IFeedbackData): FeedbackErrors {
errors.kindOther = TEXTS.errors.required;
}
if (!data.situation.trim()) {
errors.situation = TEXTS.errors.required;
} else if (data.situation.trim().length < MIN_TEXT_LENGTH) {
errors.situation = TEXTS.errors.tooShort;
// Спрашиваем только то, что реально показано для выбранного вида обращения:
// иначе форма ругалась бы на скрытое поле, и пользователь не понял бы, где ошибка.
const visible = getVisibleAppealFields(data.kind);
if (visible.situation) {
if (!data.situation.trim()) {
errors.situation = TEXTS.errors.required;
} else if (data.situation.trim().length < MIN_TEXT_LENGTH) {
errors.situation = TEXTS.errors.tooShort;
}
}
if (!data.suggestion.trim()) {
errors.suggestion = TEXTS.errors.required;
if (visible.suggestion) {
if (!data.suggestion.trim()) {
errors.suggestion = TEXTS.errors.required;
} else if (data.suggestion.trim().length < MIN_TEXT_LENGTH) {
errors.suggestion = TEXTS.errors.tooShort;
}
}
return errors;