HTML
xxxxxxxxxx
1
<div class="modal fade" id="mymodal" data-mdb-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="my modal" aria-hidden="true">
2
<div class="modal-dialog modal-dialog-scrollable modal-xl" role="document">
3
<div class="modal-content">
4
<div class="model-header">
5
Headderrr
6
</div>
7
<div class='modal-body'>
8
body
9
</div>
10
<div class="modal-footer">
11
<button class="btn btn-secondary" id='cancelMyModalBtn' type="button"
12
data-mdb-dismiss="modal">Cancel</button>
13
</div>
14
</div>
15
16
</div>
17
</div>
18
<div class='d-flex mt-2 ms-1'>
19
20
<button type="button" class="btn btn-primary" onclick="loadModal();">
21
open modal
22
</button>
23
<div class="btn-group ms-2 h-100">
24
<div class='d-flex align-items-center ms-1 me-1'>choose method: </div>
25
<input
26
type="radio"
27
class="btn-check"
28
name="options"
29
id="l1"
30
autocomplete="off"
31
checked
32
/>
33
<label class="btn btn-secondary" for="l1">Method 1 (show bad behaviour)</label>
34
35
<input type="radio" class="btn-check" name="options" id="l2" autocomplete="off" />
36
<label class="btn btn-secondary" for="l2">Method 2 - old jquery .modal (correct behave)</label>
37
38
</div>
39
</div>
40
<div class='d-flex ms-1 mt-1 text-muted'>
41
choose method (1) or (2) before you start, if already choosen method and want to change refresh the page and choose the method then start open/cancel the method, results will shown bellow:
42
</div>
43
<div class='border w-100 ms-1 mt-4 text-danger' style='background: hsl(240,40%,20%);' >
44
Console Log:
45
<div class='border ms-1 me-1 ' style='background: hsl(120,0%,70%);' id='consoleLog'>
46
</div>
47
</div>
48
<script
49
src="https://code.jquery.com/jquery-3.6.0.min.js"
50
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
51
crossorigin="anonymous"></script>
52
CSS
xxxxxxxxxx
1
.select-option:nth-child(1) > .select-option-text {
2
color: #DE3C4B;
3
}
4
5
.select-option:nth-child(2) > .select-option-text {
6
color: #1EFFBC;
7
}
8
9
.select-option:nth-child(1) {
10
background-color: #E7C8DD;
11
}
12
13
.select-option:nth-child(2) {
14
background-color: #357266;
15
}
16
17
.select-option.active:nth-child(1) {
18
background-color: #E28413;
19
}
20
21
.select-option:.active:nth-child(2) {
22
background-color: #E28413;
23
}
24
25
.select-option:nth-child(1):hover {
26
background-color: #2DE1C2;
27
}
28
29
.select-option:nth-child(2):hover {
30
background-color: #2DE1C2;
31
}
32
JS
xxxxxxxxxx
1
window.loadModal= function() {
2
if ($('#l1').prop("checked") == true)
3
window.loadModal1();
4
else
5
window.loadModal2();
6
}
7
8
window.loadModal1 = function() {
9
var myModal = new mdb.Modal(document.getElementById('mymodal'), {
10
keyboard: false
11
});
12
myModal.show();
13
14
}
15
window.loadModal2 = function() {
16
$('#mymodal').modal({
17
show: true,
18
keyboard: false
19
});
20
}
21
22
$('#l1').on("change" , function() {
23
if (window.counter > 0 )
24
alert('reload the page to get correct behaviour..');
25
$('#consoleLog').html('');
26
window.counter = 0;
27
//not working
28
//window.location = "https://mdbootstrap.com/snippets/standard/sody/3279067#js-tab-view";
29
});
30
31
$('#l2').on("change" , function() {
32
if (window.counter > 0 )
33
alert('reload the page to get correct behaviour.., check the method and start');
34
$('#consoleLog').html('');
35
window.counter = 0;
36
//not working
37
//window.location = "https://mdbootstrap.com/snippets/standard/sody/3279067#js-tab-view?m2=1";
38
});
39
40
window.counter = 0;
41
42
window.loadEventListener = function() {
43
$('#mymodal').on('hidden.mdb.modal', function (e) {
44
/* also changing this to this works: */
45
/*
46
$('#mymodal').on('hidden.bs.modal', function (e) {
47
*/
48
console.log('yeaa');
49
if (window.counter > 0)
50
$('#consoleLog').append("<br>("+parseInt(window.counter+1)+") hidded");
51
else
52
$('#consoleLog').append("("+parseInt(window.counter+1)+")hidded");
53
window.counter++;
54
});
55
}
56
57
window.loadEventListener();
58
Console errors: 0