Skip to content

fix: prevent validating empty inputs in poll forms #2780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/components/Poll/PollActions/AddCommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const AddCommentForm = ({ close, messageId }: AddCommentFormProps) => {
type: 'text',
value: ownAnswer?.answer_text ?? '',
},
validator: (value) => {
const valueString = typeof value !== 'undefined' ? value.toString() : value;
const trimmedValue = valueString?.trim();
if (!trimmedValue) {
return new Error(t('This field cannot be empty or contain only spaces'));
}
return;
},
},
}}
onSubmit={async (value) => {
Expand Down
10 changes: 6 additions & 4 deletions src/components/Poll/PollActions/SuggestPollOptionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ export const SuggestPollOptionForm = ({
value: '',
},
validator: (value) => {
if (!value) return;
const existingOption = options.find(
(option) => option.text === (value as string).trim(),
);
const valueString = typeof value !== 'undefined' ? value.toString() : value;
const trimmedValue = valueString?.trim();
if (!trimmedValue) {
return new Error(t('This field cannot be empty or contain only spaces'));
}
const existingOption = options.find((option) => option.text === trimmedValue);
if (existingOption) {
return new Error(t('Option already exists'));
}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"Submit": "Absenden",
"Suggest an option": "Eine Option vorschlagen",
"Thinking...": "Denken...",
"This field cannot be empty or contain only spaces": "Dieses Feld darf nicht leer sein oder nur Leerzeichen enthalten",
"This message did not meet our content guidelines": "Diese Nachricht entsprach nicht unseren Inhaltsrichtlinien",
"This message was deleted...": "Diese Nachricht wurde gelöscht...",
"Thread": "Thread",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"Submit": "Submit",
"Suggest an option": "Suggest an option",
"Thinking...": "Thinking...",
"This field cannot be empty or contain only spaces": "This field cannot be empty or contain only spaces",
"This message did not meet our content guidelines": "This message did not meet our content guidelines",
"This message was deleted...": "This message was deleted...",
"Thread": "Thread",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"Submit": "Enviar",
"Suggest an option": "Sugerir una opción",
"Thinking...": "Pensando...",
"This field cannot be empty or contain only spaces": "Este campo no puede estar vacío o contener solo espacios",
"This message did not meet our content guidelines": "Este mensaje no cumple con nuestras directrices de contenido",
"This message was deleted...": "Este mensaje fue eliminado...",
"Thread": "Hilo",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"Submit": "Envoyer",
"Suggest an option": "Suggérer une option",
"Thinking...": "Réflexion...",
"This field cannot be empty or contain only spaces": "Ce champ ne peut pas être vide ou contenir uniquement des espaces",
"This message did not meet our content guidelines": "Ce message ne respecte pas nos directives de contenu",
"This message was deleted...": "Ce message a été supprimé...",
"Thread": "Fil de discussion",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"Submit": "जमा करें",
"Suggest an option": "एक विकल्प सुझाव दें",
"Thinking...": "सोच रहा है...",
"This field cannot be empty or contain only spaces": "यह फ़ील्ड खाली नहीं हो सकता या केवल रिक्त स्थान नहीं रख सकता",
"This message did not meet our content guidelines": "यह संदेश हमारे सामग्री दिशानिर्देशों के अनुरूप नहीं था",
"This message was deleted...": "मैसेज हटा दिया गया",
"Thread": "रिप्लाई थ्रेड",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"Submit": "Invia",
"Suggest an option": "Suggerisci un'opzione",
"Thinking...": "Pensando...",
"This field cannot be empty or contain only spaces": "Questo campo non può essere vuoto o contenere solo spazi",
"This message did not meet our content guidelines": "Questo messaggio non soddisfa le nostre linee guida sui contenuti",
"This message was deleted...": "Questo messaggio è stato cancellato...",
"Thread": "Discussione",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"Submit": "送信",
"Suggest an option": "オプションを提案",
"Thinking...": "考え中...",
"This field cannot be empty or contain only spaces": "このフィールドは空にすることはできません。また、空白文字のみを含むこともできません",
"This message did not meet our content guidelines": "このメッセージはコンテンツガイドラインに適合していません",
"This message was deleted...": "このメッセージは削除されました...",
"Thread": "スレッド",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"Submit": "제출",
"Suggest an option": "옵션 제안",
"Thinking...": "생각 중...",
"This field cannot be empty or contain only spaces": "이 필드는 비워둘 수 없으며 공백만 포함할 수도 없습니다",
"This message did not meet our content guidelines": "이 메시지는 콘텐츠 가이드라인을 충족하지 않습니다.",
"This message was deleted...": "이 메시지는 삭제되었습니다...",
"Thread": "스레드",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"Submit": "Versturen",
"Suggest an option": "Stel een optie voor",
"Thinking...": "Denken...",
"This field cannot be empty or contain only spaces": "Dit veld mag niet leeg zijn of alleen spaties bevatten",
"This message did not meet our content guidelines": "Dit bericht voldeed niet aan onze inhoudsrichtlijnen",
"This message was deleted...": "Dit bericht was verwijderd",
"Thread": "Draadje",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"Submit": "Enviar",
"Suggest an option": "Sugerir uma opção",
"Thinking...": "Pensando...",
"This field cannot be empty or contain only spaces": "Este campo não pode estar vazio ou conter apenas espaços",
"This message did not meet our content guidelines": "Esta mensagem não corresponde às nossas diretrizes de conteúdo",
"This message was deleted...": "Esta mensagem foi excluída...",
"Thread": "Fio",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"Submit": "Отправить",
"Suggest an option": "Предложить вариант",
"Thinking...": "Думаю...",
"This field cannot be empty or contain only spaces": "Это поле не может быть пустым или содержать только пробелы",
"This message did not meet our content guidelines": "Сообщение не соответствует правилам",
"This message was deleted...": "Сообщение было удалено...",
"Thread": "Ветка",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"Submit": "Gönder",
"Suggest an option": "Bir seçenek önerin",
"Thinking...": "Düşünüyor...",
"This field cannot be empty or contain only spaces": "Bu alan boş olamaz veya sadece boşluk içeremez",
"This message did not meet our content guidelines": "Bu mesaj içerik yönergelerimize uygun değil",
"This message was deleted...": "Bu mesaj silindi...",
"Thread": "Konu",
Expand Down