1515
1616import { createGlossary , deleteGlossary , getGlossary , updateGlossary } from '../api' ;
1717import { addElement , pushNotification } from '../../../../assets/src/utils' ;
18+ import bootstrap , { Modal } from 'bootstrap' ;
1819
1920export const handleDeleteGlossary = ( ) : void => {
2021 const deleteButtons : NodeListOf < HTMLButtonElement > = document . querySelectorAll ( '.pmf-admin-delete-glossary' ) ;
@@ -42,7 +43,6 @@ export const handleDeleteGlossary = (): void => {
4243export const handleAddGlossary = ( ) : void => {
4344 const saveGlossaryButton = document . getElementById ( 'pmf-admin-glossary-add' ) as HTMLButtonElement | null ;
4445 const modal = document . getElementById ( 'addGlossaryModal' ) as HTMLElement | null ;
45- const modalBackdrop : HTMLCollectionOf < Element > = document . getElementsByClassName ( 'modal-backdrop fade show' ) ;
4646
4747 if ( saveGlossaryButton ) {
4848 saveGlossaryButton . addEventListener ( 'click' , async ( event : Event ) => {
@@ -57,11 +57,13 @@ export const handleAddGlossary = (): void => {
5757
5858 if ( response ) {
5959 if ( modal ) {
60- modal . style . display = 'none' ;
61- modal . classList . remove ( 'show' ) ;
62- }
63- if ( modalBackdrop [ 0 ] ) {
64- modalBackdrop [ 0 ] . parentNode ?. removeChild ( modalBackdrop [ 0 ] ) ;
60+ // Close modal properly using Bootstrap
61+ const bootstrapModal = bootstrap . Modal . getInstance ( modal ) as Modal ;
62+ bootstrapModal . hide ( ) ;
63+
64+ // Reset form fields for the next entry
65+ ( document . getElementById ( 'item' ) as HTMLInputElement ) . value = '' ;
66+ ( document . getElementById ( 'definition' ) as HTMLInputElement ) . value = '' ;
6567 }
6668
6769 const tableBody = document . querySelector ( '#pmf-admin-glossary-table tbody' ) as HTMLElement ;
@@ -130,7 +132,6 @@ export const onOpenUpdateGlossaryModal = (): void => {
130132export const handleUpdateGlossary = ( ) : void => {
131133 const updateGlossaryButton = document . getElementById ( 'pmf-admin-glossary-update' ) as HTMLButtonElement | null ;
132134 const modal = document . getElementById ( 'updateGlossaryModal' ) as HTMLElement | null ;
133- const modalBackdrop : HTMLCollectionOf < Element > = document . getElementsByClassName ( 'modal-backdrop fade show' ) ;
134135
135136 if ( updateGlossaryButton ) {
136137 updateGlossaryButton . addEventListener ( 'click' , async ( event : Event ) : Promise < void > => {
@@ -146,11 +147,9 @@ export const handleUpdateGlossary = (): void => {
146147
147148 if ( response ) {
148149 if ( modal ) {
149- modal . style . display = 'none' ;
150- modal . classList . remove ( 'show' ) ;
151- }
152- if ( modalBackdrop [ 0 ] ) {
153- modalBackdrop [ 0 ] . parentNode ?. removeChild ( modalBackdrop [ 0 ] ) ;
150+ // Close modal properly using Bootstrap
151+ const bootstrapModal = bootstrap . Modal . getInstance ( modal ) as Modal ;
152+ bootstrapModal . hide ( ) ;
154153 }
155154
156155 const itemLink = document . querySelector (
0 commit comments