networks: Fix focusing on network interface field on error

- In create/edit network connection form, if the accordion is closed for
'General' section, Network Interface has not be selected yet and Submit button
is pressed, 'General' section should be expanded and focus should go to Network
Interface field. This is not working as expected as the code to expand
accordions didn't match 'select' type input fields properly. Fix this.

- Declare a common class name for both create and edit forms to make writing
queries easier.

- Drop console logs that where meant for debugging.

Tests:

- On both create and edit connection forms, set the value of network interface
to '--select--' and collapse the 'General' section. Press submit. The 'General'
section is expanded, Network Interface field is focus and scrolled into view.

- Do the same check for another field such as Connection Name and that works
too.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa authored and Veiko Aasa committed 2024-09-08 19:34:44 +03:00
1 parent a1070bf319
commit 86c08e56ca
3 files changed
+3 -5

No files matched your search

+1 -3
View File
@@ -103,7 +103,7 @@ jQuery(function($) {
// collapsible so that the form element can be highlighted and an error tooltip
// can be show by the browser.
document.addEventListener('DOMContentLoaded', event => {
const selector = '.form-connection-edit input, .form-connection-create input';
const selector = '.form-connection input, .form-connection select';
const input_elements = document.querySelectorAll(selector);
input_elements.forEach(input =>
input.addEventListener('invalid', on_invalid_event)
@@ -112,9 +112,7 @@ document.addEventListener('DOMContentLoaded', event => {
function on_invalid_event(event) {
const element = event.target;
console.log('Invalid event on element', element);
const parent = element.closest('.collapse');
console.log('Invalid event with parent', parent);
// Don't use .collapse(). Instead, expand all the sections with errors.
parent.classList.add('show');
}