Skip to content

Commit

Permalink
add showModalPreselectTab
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Feb 7, 2024
1 parent df52e3a commit 670497f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/util/modal/showModal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Modal } from 'bootstrap';
import { Modal, Tab } from 'bootstrap'

/**
* Show Bootstrap modal with given ID.
Expand All @@ -18,10 +18,27 @@ export function showModalIfExist(modalId : string) : boolean {
return showModalInternal(modalId, true)
}

/**
* Show Bootstrap modal with given ID, and preselect the tab with the given ID.
* Throws error if no HTML element with the given ID was found.
* @param modalId HTML element ID of modal dialog
* @param tabId HTML element ID of tab to preselect
*/
export function showModalPreselectTab(modalId: string, tabId: string) : void {
showModal(modalId)
const tabElement = document.querySelector(`#${tabId}`)
if (tabElement) {
new Tab(tabElement).show()
}
else {
throw new Error(`Tab '#${tabId}' not found.`)
}
}

function showModalInternal(modalId : string, ignoreError? : boolean) : boolean {
const modalElement = document.getElementById(modalId)
const modalElement = document.querySelector(`#${modalId}`)
if (modalElement) {
new Modal(modalElement as Element).show()
new Modal(modalElement).show()
return true
}
else if (ignoreError) {
Expand Down

0 comments on commit 670497f

Please sign in to comment.