Skip to content

Commit 6bc4f35

Browse files
authored
fix: show errors when inputs are incorrect (#204)
* fix: show errors when inputs are incorrect * chore: bump __init__.py version
1 parent a27b9e4 commit 6bc4f35

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

poll/public/css/poll_edit.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@
4646
float: right;
4747
}
4848

49+
#poll-error-container {
50+
background-color: #f8d7da;
51+
border: 1px solid #f5c6cb;
52+
color: #721c24;
53+
padding: 10px;
54+
margin: 10px 0;
55+
border-radius: 4px;
56+
font-weight: 500;
57+
display: none;
58+
cursor: pointer;
59+
}
60+
61+
#poll-error-container:hover {
62+
background-color: #f5c2c7;
63+
transition: background-color 0.3s ease;
64+
}
65+
66+
#poll-error-container:before {
67+
content: "⚠️ ";
68+
}
69+
70+
#poll-error-message {
71+
display: inline-block;
72+
margin-top: 5px;
73+
}
74+
4975
.poll-setting-label {
5076
text-transform: capitalize;
5177
}

poll/public/html/poll_edit.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ <h2><label for="poll-feedback-editor">{% trans 'Feedback' %}</label></h2>
107107
<li class="action-item">
108108
<a href="#" class="button cancel-button">{% trans 'Cancel' %}</a>
109109
</li>
110+
<li class="error-message" id="poll-error-container" title="Click to dismiss">
111+
<span class="action-item" id="poll-error-message"></span>
112+
</li>
110113
</ul>
111114
</div>
112115
</form>

poll/public/js/poll_edit.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ function PollEditUtil(runtime, element, pollType) {
1414
// Set up the editing form for a Poll or Survey.
1515
var temp = $('.poll-form-component', element).html();
1616

17+
// Hide error container initially
18+
$('#poll-error-container', element).hide();
19+
20+
// Allow clicking on the error message to dismiss it
21+
$('#poll-error-container', element).click(function() {
22+
$(this).hide();
23+
});
24+
1725
PollCommonUtil.init(Handlebars);
1826

1927
self.answerTemplate = Handlebars.compile(temp);
@@ -234,6 +242,8 @@ function PollEditUtil(runtime, element, pollType) {
234242
data['private_results'] = eval($('#poll-private-results', element).val());
235243

236244
if (notify) {
245+
// Hide any previous error messages
246+
$('#poll-error-container', element).hide();
237247
runtime.notify('save', {state: 'start', message: gettext("Saving")});
238248
}
239249
$.ajax({
@@ -246,9 +256,14 @@ function PollEditUtil(runtime, element, pollType) {
246256
if (result['success'] && notify) {
247257
runtime.notify('save', {state: 'end'})
248258
} else if (notify) {
259+
// Format and display the error message
260+
var errorMessage = self.format_errors(result['errors']);
261+
$('#poll-error-message', element).html(errorMessage);
262+
$('#poll-error-container', element).show();
263+
249264
runtime.notify('error', {
250265
'title': 'Error saving poll',
251-
'message': self.format_errors(result['errors'])
266+
'message': errorMessage
252267
});
253268
}
254269
}

0 commit comments

Comments
 (0)