From 714c0a6cfd3368820753335bf1f1c8d5a9c00ffe Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 23 Mar 2023 10:23:19 -0500 Subject: [PATCH] Avoid accidental auto-submit of new msg form, for subject field --- tailbone/templates/deform/textarea.pt | 3 ++- tailbone/templates/messages/create.mako | 13 +++++++++++++ tailbone/views/messages.py | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/tailbone/templates/deform/textarea.pt b/tailbone/templates/deform/textarea.pt index f705c652..bb9b6c84 100644 --- a/tailbone/templates/deform/textarea.pt +++ b/tailbone/templates/deform/textarea.pt @@ -9,7 +9,8 @@
+ v-model="${vmodel}" + tal:attributes="attributes|field.widget.attributes|{};">
diff --git a/tailbone/templates/messages/create.mako b/tailbone/templates/messages/create.mako index 10729590..4a15573b 100644 --- a/tailbone/templates/messages/create.mako +++ b/tailbone/templates/messages/create.mako @@ -44,6 +44,19 @@ TailboneFormData.possibleRecipients = new Map(${json.dumps(available_recipients)|n}) TailboneFormData.recipientDisplayMap = ${json.dumps(recipient_display_map)|n} + TailboneForm.methods.subjectKeydown = function(event) { + + // do not auto-submit form when user presses enter in subject field + if (event.which == 13) { + event.preventDefault() + + // set focus to msg body input if possible + if (this.$refs.messageBody && this.$refs.messageBody.focus) { + this.$refs.messageBody.focus() + } + } + } + diff --git a/tailbone/views/messages.py b/tailbone/views/messages.py index 6aaf342e..4c83da34 100644 --- a/tailbone/views/messages.py +++ b/tailbone/views/messages.py @@ -221,11 +221,13 @@ class MessageView(MasterView): if self.creating: f.set_widget('subject', dfwidget.TextInputWidget( placeholder="please enter a subject", - autocomplete='off')) + autocomplete='off', + attributes={'@keydown.native': 'subjectKeydown'})) f.set_required('subject') # body - f.set_widget('body', dfwidget.TextAreaWidget(cols=50, rows=15)) + f.set_widget('body', dfwidget.TextAreaWidget( + cols=50, rows=15, attributes={'ref': 'messageBody'})) if self.creating: f.remove('sender', 'sent')