22import { Icon } from ' astro-icon/components' ;
33---
44
5- <div class =" flex flex-col border border-zinc-300 dark:border-zinc-700 p-3 rounded-xl w-72 " >
5+ <div class =" flex flex-col border border-zinc-300 dark:border-zinc-700 p-3 rounded-xl w-80 " >
66 <div id =" vote-buttons" class =" flex gap-4 mx-auto" >
77 <span >{ Astro .locals .t (' feedback.question' )} </span >
88 <div class =" flex gap-3" >
@@ -19,6 +19,7 @@ import { Icon } from 'astro-icon/components';
1919 rows =" 3"
2020 maxlength =" 250"
2121 placeholder ={ Astro .locals .t (' feedback.placeholder' )} ></textarea >
22+ <span id =" feedback-error" class =" hidden text-sm text-red-500" >{ Astro .locals .t (' feedback.required' )} </span >
2223 </div >
2324 <button
2425 id =" submit-button"
@@ -49,6 +50,10 @@ import { Icon } from 'astro-icon/components';
4950 return document.getElementById('feedback-comment') as HTMLTextAreaElement;
5051 }
5152
53+ function getErrorMessage(): HTMLElement {
54+ return document.getElementById('feedback-error') as HTMLElement;
55+ }
56+
5257 getLikeButton()?.addEventListener('click', function() {
5358 toggleForm('like');
5459 });
@@ -68,6 +73,10 @@ import { Icon } from 'astro-icon/components';
6873 }
6974 });
7075
76+ getCommentTextarea()?.addEventListener('input', function() {
77+ getErrorMessage().classList.add('hidden');
78+ });
79+
7180 function toggleForm(type: FeedbackType): void {
7281 const feedbackForm = getFeedbackForm();
7382 const activeClass = 'text-accent-700';
@@ -83,6 +92,7 @@ import { Icon } from 'astro-icon/components';
8392 getLikeButton().classList.remove(activeClass);
8493 getDislikeButton().classList.remove(activeClass);
8594 getCommentTextarea().value = '';
95+ getErrorMessage().classList.add('hidden');
8696 return;
8797 }
8898
@@ -99,6 +109,14 @@ import { Icon } from 'astro-icon/components';
99109 }
100110
101111 async function submitFeedback() {
112+ const comment = getCommentTextarea().value.trim();
113+
114+ if (!comment) {
115+ getErrorMessage().classList.remove('hidden');
116+ getCommentTextarea().focus();
117+ return;
118+ }
119+
102120 const host = import.meta.env.PUBLIC_DIRECTUS_HOST;
103121 const feedbackType = getFeedbackForm().dataset.feedbackType as FeedbackType;
104122
@@ -115,7 +133,7 @@ import { Icon } from 'astro-icon/components';
115133 createItem('feedback' as never, {
116134 type: feedbackType,
117135 page: window.location.pathname,
118- comment: getCommentTextarea().value ,
136+ comment: comment ,
119137 })
120138 );
121139 } catch (error) {
0 commit comments