From 44586743ea410e9df11d88ca3580ccc08a71bd17 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 19 Jul 2022 14:21:20 -0400 Subject: [PATCH] Fixes #9437: Standardize form submission buttons and behavior when using enter key --- docs/release-notes/version-3.2.md | 1 + netbox/project-static/dist/netbox.js | Bin 376156 -> 375907 bytes netbox/project-static/dist/netbox.js.map | Bin 345579 -> 345348 bytes netbox/project-static/src/forms/elements.ts | 40 +--------------- .../circuits/circuittermination_edit.html | 14 ------ netbox/templates/dcim/interface_edit.html | 11 ----- netbox/templates/generic/bulk_delete.html | 2 +- netbox/templates/generic/bulk_edit.html | 2 +- netbox/templates/generic/bulk_import.html | 12 ++--- netbox/templates/generic/bulk_remove.html | 2 +- netbox/templates/generic/bulk_rename.html | 2 +- .../templates/generic/confirmation_form.html | 45 +++++++----------- netbox/templates/generic/object_edit.html | 8 ++-- netbox/templates/generic/object_import.html | 30 ++++++------ .../virtualization/vminterface_edit.html | 11 ----- 15 files changed, 49 insertions(+), 131 deletions(-) diff --git a/docs/release-notes/version-3.2.md b/docs/release-notes/version-3.2.md index 6718fc247..7b9adb374 100644 --- a/docs/release-notes/version-3.2.md +++ b/docs/release-notes/version-3.2.md @@ -9,6 +9,7 @@ ### Bug Fixes +* [#9437](https://github.com/netbox-community/netbox/issues/9437) - Standardize form submission buttons and behavior when using enter key * [#9634](https://github.com/netbox-community/netbox/issues/9634) - Fix image URLs in rack elevations when using external storage * [#9715](https://github.com/netbox-community/netbox/issues/9715) - Fix `SOCIAL_AUTH_PIPELINE` config parameter not taking effect * [#9754](https://github.com/netbox-community/netbox/issues/9754) - Fix regression introduced by #9632 diff --git a/netbox/project-static/dist/netbox.js b/netbox/project-static/dist/netbox.js index 3b9d253c910687cab913fa4410ebf02d56259832..9ea2e5c7c51459ff2a2b51720f271929a0119eb8 100644 GIT binary patch delta 3383 zcmb7GdstOf7XQ|{dz(sF#zRR(K*W3F=twe-f!E}ra+UW(c}ViQyzb>(4qQOEV4{+s z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r$*pMx^3HWwY0+xRdYYn@=H>?aG@so_ANT7q zXDcY+;~Qz1f6Bu#BTb==G{Qf&mxIzqtk-CDOC$ZcKPI(t3tg=J0QBEZYp~wc*4OF3 zHEcRSR|$~F4R25rx=wt9&O~T?11U}90Sexyn@>|{4#GACJ1dTl>7aias0Ef?ym0KD zr;)cSbU0trK}Tv4+p+qYT$K_azc!^`-*meqm0^*@@rxbw1)TNfPU?gtb#Eu_>hoW! C?*+2} diff --git a/netbox/project-static/dist/netbox.js.map b/netbox/project-static/dist/netbox.js.map index 5a78b64f1000be47875ef11fdecfa3e13886291a..60656bc6d6f3450acca6ca6d4369da29b4749527 100644 GIT binary patch delta 49 zcmaFeE!xs0+R(z-!qmdNg(cOOr64uKdApz=iy|Xau*dW~f0k-CU*|GsbJy)({8_$# F1pt|^5fA_X delta 281 zcmXw!F^j@L5QS0G$(8;9Yez&l5y9ro=t)>|i^Lc$#Rvu>h+ZQWTBN$O_m2qvC~LXa zOoGkwcHev7&ZNJ!$6xK7meO)sxj8HEw2Rh4b6_Jh0uD?9X%AF;>hhgz0|i;<$g*&t7tG(M4-I})1DzozJjHgftYEmEEj%{ua|G - * Save & Continue - * - * ``` - * - * @param event Click event. - */ -function handleSubmitWithReturnUrl(event: MouseEvent): void { - const element = event.target as HTMLElement; - if (element.tagName === 'BUTTON') { - const button = element as HTMLButtonElement; - const action = button.getAttribute('return-url'); - const form = button.form; - if (form !== null && isTruthy(action)) { - form.action = action; - form.submit(); - } - } -} +import { getElements, scrollTo } from '../util'; function handleFormSubmit(event: Event, form: HTMLFormElement): void { // Track the names of each invalid field. @@ -57,15 +29,6 @@ function handleFormSubmit(event: Event, form: HTMLFormElement): void { } } -/** - * Attach event listeners to form buttons with the `return-url` attribute present. - */ -function initReturnUrlSubmitButtons(): void { - for (const button of getElements('button[return-url]')) { - button.addEventListener('click', handleSubmitWithReturnUrl); - } -} - /** * Attach an event listener to each form's submitter (button[type=submit]). When called, the * callback checks the validity of each form field and adds the appropriate Bootstrap CSS class @@ -82,5 +45,4 @@ export function initFormElements(): void { submitter.addEventListener('click', (event: Event) => handleFormSubmit(event, form)); } } - initReturnUrlSubmitButtons(); } diff --git a/netbox/templates/circuits/circuittermination_edit.html b/netbox/templates/circuits/circuittermination_edit.html index f8393f945..8919bbd66 100644 --- a/netbox/templates/circuits/circuittermination_edit.html +++ b/netbox/templates/circuits/circuittermination_edit.html @@ -48,17 +48,3 @@ {% render_field form.description %} {% endblock %} - -{# Override buttons block, 'Create & Add Another'/'_addanother' is not needed on a circuit. #} -{% block buttons %} - Cancel - {% if object.pk %} - - {% else %} - - {% endif %} -{% endblock buttons %} diff --git a/netbox/templates/dcim/interface_edit.html b/netbox/templates/dcim/interface_edit.html index ddda1ae31..62aa54ef3 100644 --- a/netbox/templates/dcim/interface_edit.html +++ b/netbox/templates/dcim/interface_edit.html @@ -91,14 +91,3 @@ {% endif %} {% endblock %} - -{% block buttons %} - Cancel - {% if object.pk %} - - - {% else %} - - - {% endif %} -{% endblock %} diff --git a/netbox/templates/generic/bulk_delete.html b/netbox/templates/generic/bulk_delete.html index 1bcc2db1d..edc5132ce 100644 --- a/netbox/templates/generic/bulk_delete.html +++ b/netbox/templates/generic/bulk_delete.html @@ -36,8 +36,8 @@ Context: {{ field }} {% endfor %}
- Cancel + Cancel
diff --git a/netbox/templates/generic/bulk_edit.html b/netbox/templates/generic/bulk_edit.html index 362644135..cea50eaff 100644 --- a/netbox/templates/generic/bulk_edit.html +++ b/netbox/templates/generic/bulk_edit.html @@ -118,8 +118,8 @@ Context:
- Cancel + Cancel
diff --git a/netbox/templates/generic/bulk_import.html b/netbox/templates/generic/bulk_import.html index 1a85c3a21..1d638cb2c 100644 --- a/netbox/templates/generic/bulk_import.html +++ b/netbox/templates/generic/bulk_import.html @@ -44,12 +44,12 @@ Context:
-
- {% if return_url %} - Cancel - {% endif %} - -
+
+ + {% if return_url %} + Cancel + {% endif %} +
{% if fields %} diff --git a/netbox/templates/generic/bulk_remove.html b/netbox/templates/generic/bulk_remove.html index 0bda6adbc..6dc102b5a 100644 --- a/netbox/templates/generic/bulk_remove.html +++ b/netbox/templates/generic/bulk_remove.html @@ -23,8 +23,8 @@ {{ field }} {% endfor %}
- Cancel + Cancel
diff --git a/netbox/templates/generic/bulk_rename.html b/netbox/templates/generic/bulk_rename.html index 134d3df5a..ef6b18cae 100644 --- a/netbox/templates/generic/bulk_rename.html +++ b/netbox/templates/generic/bulk_rename.html @@ -34,11 +34,11 @@
- Cancel {% if '_preview' in request.POST and not form.errors %} {% endif %} + Cancel
diff --git a/netbox/templates/generic/confirmation_form.html b/netbox/templates/generic/confirmation_form.html index c4c15f7e7..e9d3d01aa 100644 --- a/netbox/templates/generic/confirmation_form.html +++ b/netbox/templates/generic/confirmation_form.html @@ -2,33 +2,24 @@ {% load form_helpers %} {% block content %} -
- -
- -
- {% csrf_token %} - {% for field in form.hidden_fields %} - {{ field }} - {% endfor %} - -
-
{% block confirmation_title %}{% endblock %}
- -
- {% block message %}

Are you sure?

{% endblock %} -
- - - -
- -
- +
+
+
+ {% csrf_token %} + {% for field in form.hidden_fields %} + {{ field }} + {% endfor %} +
+
{% block confirmation_title %}{% endblock %}
+
+ {% block message %}

Are you sure?

{% endblock %} +
+
- +
+
{% endblock %} diff --git a/netbox/templates/generic/object_edit.html b/netbox/templates/generic/object_edit.html index 06308e9ef..892c7d2b1 100644 --- a/netbox/templates/generic/object_edit.html +++ b/netbox/templates/generic/object_edit.html @@ -94,19 +94,19 @@ Context:
{% block buttons %} - Cancel {% if object.pk %} {% else %} - + {% endif %} + Cancel {% endblock buttons %}
diff --git a/netbox/templates/generic/object_import.html b/netbox/templates/generic/object_import.html index ffa16b4c2..4d54fde61 100644 --- a/netbox/templates/generic/object_import.html +++ b/netbox/templates/generic/object_import.html @@ -5,19 +5,19 @@ {% block title %}{{ obj_type|bettertitle }} Import{% endblock %} {% block content %} -
-
-
- {% csrf_token %} - {% render_form form %} -
- {% if return_url %} - Cancel - {% endif %} - - -
-
-
-
+
+
+
+ {% csrf_token %} + {% render_form form %} +
+ + + {% if return_url %} + Cancel + {% endif %} +
+
+
+
{% endblock content %} diff --git a/netbox/templates/virtualization/vminterface_edit.html b/netbox/templates/virtualization/vminterface_edit.html index 496960a64..316900865 100644 --- a/netbox/templates/virtualization/vminterface_edit.html +++ b/netbox/templates/virtualization/vminterface_edit.html @@ -55,14 +55,3 @@
{% endif %} {% endblock %} - -{% block buttons %} - Cancel - {% if object.pk %} - - - {% else %} - - - {% endif %} -{% endblock %}