본문 바로가기
Web/JavaScript

sweetAlert 두 번 띄울때 2번째 알럿 안뜨는 문제 - 확인 버튼 눌러도 닫히지 않게 설정해서 해결!

by reumiii 2020. 11. 5.

찾다보니 알럿을 두개 띄우는 더 좋은 방법을 알게되었다!

 

swal("첫 번째 알럿") 
.then((value) => { 
	swal("두 번째 알럿") 
});

더 간단!ㅎㅎ

 

 

 

------------------- 이전에 썼던 방법 -----------------------

 

 

sweetAlert을 사용하여 2번의 확인 alert를 연달아 띄워야하는데

첫번째 alert만 뜨고 두번째 alert는 뜨지 않는 문제가 생겼다.

 

첫번째 alert에서 확인을 누르면 두번째 alert이 떠야하지만

확인을 누르는 순간 alert를 close해버리기 때문에 두번째 alert가 보여지지 않고 닫혀버리는 것이다.

 

 

 

그래서 해결방법은...!

첫번째 alert에서 확인을 눌렀을때 alert을 닫지 않도록 설정해야한다.

그래서 두번째 alert이 보이도록!

 

 

그렇게 설정하기 위해서는

closeOnConfirm:false;

-> 이 옵션을 추가하면된다!

 

function firstAlert(){
		swal({
			  title: "First Alert",
			  text: "첫 번째 알럿입니다!",
			  icon: "warning",
			  buttons: true,
			  showCancelButton: true,
			  closeOnConfirm: false, ///확인버튼 클릭 시 알럿이 close되지 않게 설정
			  confirmButtonText : "확인",
			  cancelButtonText : "취소"
			},
			function(isConfirm){
			  secondAlert(); //확인을 누르면 두번째 sweeet alert을 띄움!
		});
}


function secondAlert(){
	if(true){
    	swal({
			  title: "Second Alert",
			  text: "두 번째 알럿입니다!",
			  icon: "warning",
			  buttons: true,
			  showCancelButton: true,
			  confirmButtonText : "확인",
			  cancelButtonText : "취소"
			},
			function(isConfirm){
		});
    }else{
    	swal.close();
    }
}
        

 

 

댓글