I utilize Bootbox to open a dialog, it has one dropdown list for end user to select. And click Import button after select dropdown list.
The code snippet looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | bootbox.dialog({ title: '匯入專案', buttons: { importProject: { label: '匯入', className: 'btn-primary', callback: function() { var projectSelectedVal = document.getElementById("projectList").value; var importOptionVal = document.querySelector('input[name="importOption"]:checked').value; if (projectSelectedVal == '') { bootbox.alert('<font color=red><b>請選擇要匯入的專案</b></font>'); } else { // do something } } }, cancel: { label: '取消' } } }); |
If end user do not select required attribute, I will show warning message to end user. But the Bootbox dialog will close it automatically, how do I keep the dialog open?
How-to
Here has updated code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | bootbox.dialog({ title: '匯入專案', buttons: { importProject: { label: '匯入', className: 'btn-primary', callback: function() { var projectSelectedVal = document.getElementById("projectList").value; var importOptionVal = document.querySelector('input[name="importOption"]:checked').value; if (projectSelectedVal == '') { bootbox.alert('<font color=red><b>請選擇要匯入的專案</b></font>'); return false; } else { // do something } } }, cancel: { label: '取消' } } }); |