์๋ ํ์ธ์,
์ด ๋ฌ์ฝคํ ๋ณ๊ฒฝ ์ ํ๊ฐ ์์ต๋๋ค.
var self = this;
swal({
title : $.t('modal.clear.title') || "Etes vous sรปr ?",
text : $.t('modal.clear.text') || "Le formulaire sera dรฉfinitivement perdu !",
type : "warning",
showCancelButton : true,
confirmButtonColor : "#DD6B55",
confirmButtonText : $.t('modal.clear.yes') || "Oui, supprimer",
cancelButtonText : $.t('modal.clear.no') || "Annuler",
closeOnCancel : true
}, function(isConfirm) {
if (isConfirm){
// I Use backbone radio event
self.homePageChannel.trigger('deleteForm', self.currentSelectedForm)
}
});
์ฝ๋ฐฑ์์ ๋ฐฑ๋ณธ ๋ผ๋์ค๋ก ์ด๋ฒคํธ๋ฅผ ๋ณด๋
๋๋ค.
์ด ์์ ์์ ๋ชจ๋ ๊ฒ์ด ์ข์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋ด ์ด๋ฒคํธ ์๋ต์์ ๋ค์๊ณผ ๊ฐ์ ๋ ๋ค๋ฅธ ๋ฌ์ฝคํ ๊ฒฝ๊ณ ๋ฅผ ํ์ํ๊ณ ์ถ์ต๋๋ค.
formDeleted : function(result) {
swal({
title : $.t('modal.deleted.title') || 'Formulaire supprimรฉ !',
text : $.t('modal.deleted.text') || 'Votre formulaire a รฉtรฉ supprimรฉ avec succรจs',
type : "success",
});
},
๊ทธ๋ฆฌ๊ณ ๋ ๋ฒ์งธ ๋ฌ์ฝคํ ๊ฒฝ๊ณ ๋ ๋ํ๋์ง ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ formDeleted ํจ์๊ฐ ์คํ๋๊ณ ์๋ค๊ณ ํ์ ํฉ๋๋ค.
๋น์ ์ ๋์์ ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค
JSFiddle์์ ์ฝ๋๋ฅผ ๋ณด์ฌ์ค ์ ์์ต๋๊น?
JSFiddle์ ๋ง๋ค์์ต๋๋ค : http://jsfiddle.net/5pj7wwx9/
๋ฒํผ์ ํด๋ฆญํ๋ฉด ์ฒซ ๋ฒ์งธ sweetAlert๊ฐ ํ์๋๊ณ ์ฝ๋ฐฑ์ด ํธ์ถ๋์ง๋ง ๋ ๋ฒ์งธ sweetAlert๋ ์์ต๋๋ค.
setTimeout์ผ๋ก ์๋ํ JSFiddle์์ 2 ์ด ํ์ ์๋ํฉ๋๋ค.
์ด ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์ด๋ฅผ ๋ถ๋ฅํ๋ ๋ฐ ํ์ํ ์ ๋ณด๋ฅผ ๊ธฐ๊บผ์ด ์ ๊ณตํฉ๋๋ค.
๋ฌธ์ ์ ํ์ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ +1
์ด๊ฒ์ด ๋๊ตฌ์๊ฒ๋ ๋์์ด ๋ ์ ์์ต๋๋ค. ์ ๊ฒฝ์ฐ์๋ closeOnCancel
๋ฐ / ๋๋ closeOnConfirm
์ false
๋ก ์ค์ ํ์ฌ์ด๋ฅผ ์ ๋ ฌ ํ ์์์์ต๋๋ค. ๋ฐ๋ผ์ ๋ ๋ฒ์งธ ๊ฒฝ๊ณ ์์๊ฐ ๋ซํ๋ ๊ฒ์ ๋ฐฉ์งํฉ๋๋ค. ๋ ๋ฒ์งธ swal ํธ์ถ์ true
์ค์ ํ ์ ์์ต๋๋ค.
์ด๋ ์ฌ๋ฐ๋ฅธ ๋์์ด ์๋๋ฏ๋ก closeOnCancel ๋ฐ closeOnConfirm์ ๊ฐ์ ์์กดํด์๋ ์๋ฉ๋๋ค.
๋์ํ์ง๋ง closeOnConfirm
์ ์๋ ๋ ๋ชฉ์ ์ผ ์ ์์ต๋๋ค. ๋ ๋ฒ์งธ ์์๋ฅผ ์ฌ๋ swal ์์ (http://tristanedwards.me/sweetalert)์์๋ ๊ทธ๋ ๊ฒ ํํ ๋์๊ธฐ ๋๋ฌธ์
๋๋ค.
๋๋ ๊ทธ๊ฒ์ด ํ์คํ ์ง๊ด์ ์ด์ง ์๋ค๋ ๋ฐ ์ฌ์ ํ ๋์ํฉ๋๋ค.
์ ์๊ฒ๋ ์๋ํ์ง ์์ต๋๋ค. ๋ด๊ฐ ๋ง๋ ๋ฐ์ด์ฌ๋ฆฐ์ ๋ณผ ์ ์์ต๋๋ค. https://jsfiddle.net/madhureng/5pj7wwx9/16/
๋๋ API๊ฐ ๋๋ฅผ ์ํด ๊ฒฐ์ ์ ๋ด๋ฆฌ๋ ๊ฒ๋ณด๋ค ์์ ๋๋ ๊ฒ์ด ๋ ํ๋ณต ํ ๊ฒ์ ๋๋ค.
@ maddy2308- ํด๋ฆญ์ด ๋๋ฌด ๋ง์ต๋๋ค. ์๋ํฉ๋๋ค.
์ด ๋ฐ์ด์ฌ๋ฆฐ์ ํ์ธํ์ญ์์ค : https://jsfiddle.net/g8j1acv4/
๋ด๊ฐ ๋ณ๊ฒฝ ํ ๊ฒ์ ์ฒซ ๋ฒ์งธ ๋ฌธ์๋ฅผ ๊บผ๋ด์ document.ready๋ก ๋ณ๊ฒฝ ํ ๊ฒ๋ฟ์ ๋๋ค.
@joenorton์ด ์ง์ ํ๋ฏ์ด ์ด๊ฒ์ด closeOnConfirm: false
๋ชฉ์ ์
๋๋ค. ๋๋ ๊ทธ๊ฒ์ด ์กฐ๊ธ ์ง๊ด์ ์ด์ง ์๋ค๋ ๊ฒ์ ๋์ํ๋ค. ๊ทธ๋์ ๋๊ตฐ๊ฐ๊ฐ ๋ฌธ์ ์ ๋ํ ํด๊ฒฐ์ฑ
์ ๊ฐ์ง๊ณ ์๋ค๋ฉด, ๋๋ ๊ทธ๊ฒ์ ์ถ๊ฐํ๊ฒ๋์ด ๊ธฐ์๋ค!
@ maddy2308 , ๋ฐ์ด์ฌ๋ฆฐ์ ๋ฌธ์ ๋ $('button')
์ด ๋๋ฌด ๋ชจํธํ์ฌ swal์ ๋ฒํผ๋ ํธ์ถ๋๋ค๋ ๊ฒ์
๋๋ค. ๋๋ฌด $('body > button')
๋ณ๊ฒฝํ๋ฉด ์๋ํฉ๋๋ค.
๋๋์ด ๋ฌธ์ ๋ก ๊ณ ์ํ๊ณ , ์ด๊ฒ์ด ๋ณ๊ฒฝ๋์ด์ผํ๋ค๊ณ ๋ฏฟ์ต๋๋ค.
@ t4t5 ์์ค ์ฝ๋๋ฅผ
the first swal is shown at point A in time
the user interacts with the first swal at point B in time
the callback is called and invokes the second swal at point C in time
the active swal is dismissed at point D in time
์ด ๋ฌธ์ ๋ฅผ ์ฝ๊ฒ ํด๊ฒฐํ ์์๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
<strong i="11">@A</strong>: An integer variable is set that increases with every call to swal
<strong i="12">@B</strong>: The current value of the variable is remembered
<strong i="13">@D</strong>: If the variable has changed, do not call swal.close
์ด๋ ๊ฒํ๋ฉด C
์์ ํ์ฌ ์ฝ๋๋ฒ ์ด์ค๋ฅผ ๊ฑฐ์ ์์ ํ์ง ์๊ณ ๋ ์ ๋ํ ์์๋ฅผ ์ผ๋ง๋ ์ง ํธ์ถ ํ ์ ์์ต๋๋ค.
๋์ผํ ๋ฌธ์ ๊ฐ ์์๋๋ฐ ํ์ธ ์์
์ $ timeout์ ์ถ๊ฐํ์ฌ ํด๊ฒฐํ์ต๋๋ค (Angular ์ฌ์ฉ).
if (isConfirm){
return $timeout(function() {
// I Use backbone radio event
self.homePageChannel.trigger('deleteForm', self.currentSelectedForm)
}, 100);
}
์ด ๋ฒ๊ทธ๋ ๋ค์ ์ํฉ์์๋ ๋์๊ฒ ๋ฐ์ํฉ๋๋ค.
$http
์์ฒญ์ ํธ๋ฆฌ๊ฑฐํ๋ ํ์ธ ๋ฌ์ฝคํ ์๋ฆผ์ ํธ์ถํฉ๋๋ค.offline
๋ก ์ค์ ํ์ฌ $http
์์ฒญ ์ฆ์ ์คํจ๋ฅผ ๊ฐ์ ํฉ๋๋ค .$http
์คํจ์ ์ค๋ฅ ๋ฌ์ฝคํ ์๋ฆผ์ ํธ์ถํฉ๋๋ค.์ฒซ ๋ฒ์งธ ํ์ธ ๊ฒฝ๊ณ ๋ ์ ์์ ์ผ๋ก ํ์๋์ง๋ง ์ค๋ฅ ๊ฒฝ๊ณ ๋ ํ์๋์ง ์์ต๋๋ค.
์ฐธ๊ณ : ์ฝ๋๋ฅผ ์์ธํ ์ดํด ๋ณด์ง ์์์ง๋ง ๊ธฐ์กด์ ๋ฌ์ฝคํ ์๋ฆผ์ ๋ํ ๋ซ๊ธฐ ์ ๋๋ฉ์ด์ ์ ์ทจ์ํ๊ณ ์ฆ์ ์ญ์ ํด์ผํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋ฌ๋ฉด ๋ ๋ฒ์งธ ์๋ฆผ์ด ์ ์์ ์ผ๋ก ํ์๋ฉ๋๋ค.
ํธ์ง : ์์๋๋ก ๋ฌธ์ ๋ ์ฒซ ๋ฒ์งธ ๋ฌ์ฝคํ ๊ฒฝ๊ณ ํ์ธ์ ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ swal์์ animation
๋ฅผ false๋ก ์ค์ ํ๋ฉด ๋ฌธ์ ๊ฐ ์ค์ง๋ฉ๋๋ค. ๊ทธ๋ฌ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์๋ ๊ฒฝ์ฐ ์ ๋๋ฉ์ด์
์ ํ์ฑํํ๊ณ ์ถ์ ์ ์๊ธฐ ๋๋ฌธ์ ๋์๊ฒ๋ ๋ฒ๊ทธ์ฒ๋ผ ๋ณด์
๋๋ค.
๋ ๊ฐ์ง ํด๊ฒฐ์ฑ ์ ์ ์ํฉ๋๋ค.
1st : ๊ธฐ์กด ๊ฒฝ๊ณ ๊ฐ ์ ๋๋ฉ์ด์ ๋๋ ๋์ ๋ ๋ฒ์งธ ๊ฒฝ๊ณ ๊ฐ ํธ์ถ๋๋ฉด ์ ๋๋ฉ์ด์ ํ๋ก์ธ์ค๋ฅผ ์ค์งํ๊ณ ํ์ฌ ๊ฒฝ๊ณ ๋ฅผ ์ฆ์ ๋ซ๊ณ ์ ๊ฒฝ๊ณ ๋ฅผ ํ์ํฉ๋๋ค.
2nd : ๋ซ๊ธฐ ์ ๋๋ฉ์ด์ ์ด ๋๋ ๋ ์ด๋ฆฌ๋ ๋ ๋ฒ์งธ ๊ฒฝ๊ณ ๋ฅผ ํ์ ๋ฃ์ต๋๋ค.
๋ ๋ฒ์งธ ์๋ฃจ์ ์ ์ผ์ ๋ ๋งค๋๋ฝ๊ฒ ๋ง๋ค๊ณ ์ฒซ ๋ฒ์งธ ์๋ฃจ์ ์ ์ค๋ฅ ๋ชจ๋ฌ์ด ๋ ๋นจ๋ฆฌ ๋ํ๋ฉ๋๋ค!
ํ ๋ฆฌํ์คํธ๋ฅผ ์๋ํด ๋ณด ๊ฒ ์ง๋ง, ์ด์ ์์ด ํ๋ก์ ํธ์ ๊ธฐ์ฌํ ์ ์ด ์์ต๋๋ค. ๋๊ตฐ๊ฐ๊ฐ ๊ณ ์ณ์ผ ํ ๊ณณ์ ์๋ค๋ฉด ๋จผ์ ํ ๋ฆฌํ์คํธ๋ฅผ ํด์ฃผ์ธ์! :)
@ t4t5 ์ ๋ณด๊ณ ์์ ์๋ฃจ์ ์ ์ดํด๋ณด์ญ์์ค. ์น์ธํ๋ฉด ์ ๊ฐ ์์ ํ ์ ์์ต๋๋ค!
querySelectorAll ์ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ ๋ชจ๋ ์์๋ฅผ โโ๋ฐํํ๋ฏ๋ก ๋ฐํ ๋ ๊ฐ์ ๋ฐ๋ณต ํ ์ ์์ต๋๋ค.
var alertBtn = document.querySelectorAll('.js-alert');
for (var i = 0; i < alertBtn.length; i++) {
alertBtn[i].onclick = function(){
swal({
title: "text",
text: "text text"
});
};
}
๋ด SweetAlert์ ๋์ผํ ๋ฌธ์ ๊ฐ ์์๋๋ฐ, ๋ ๋ฒ์งธ swal์ด ๋ํ๋์ผ ํ ๋๋ ์๋ฉ๋๋ค. ๋ด ํจ์์ $ timeout์ ํฌํจํ์ฌ ํด๊ฒฐ ๋ ๋ฌธ์ ์ ๋๋ค.
function(error) {
console.log(error);
$timeout(function(){
SweetAlert.error('Erro');
},100) }
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์์ง๋ง @PommeVerte์ ์๋ฃจ์
์ผ๋ก ํด๊ฒฐ๋์์ต๋๋ค. ๋ถ๋ชจ swal ()์ closeOnCancel: false
์ ์ค์ ํด์ผํ์ต๋๋ค.
SweetAlert 2.0๋ถํฐ๋ SweetAlert๋ฅผ ์ฐ๊ฒฐํ๋ ๋ฐ closeOnConfirm
๋ฐ closeOnCancel
๊ฐ ๋ ์ด์ ํ์ํ์ง ์์ต๋๋ค. ์ฝ์์ ์ฌ์ฉํ์ญ์์ค! :)
SetTimeout์ ์ฝ๋ฐฑ ํ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ง๋ง ๋ฌธ์ ์ ์์ธ์ ๋ํด ๋ ์๊ณ ์ถ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์ด ๋๊ตฌ์๊ฒ๋ ๋์์ด ๋ ์ ์์ต๋๋ค. ์ ๊ฒฝ์ฐ์๋
closeOnCancel
๋ฐ / ๋๋closeOnConfirm
์false
๋ก ์ค์ ํ์ฌ์ด๋ฅผ ์ ๋ ฌ ํ ์์์์ต๋๋ค. ๋ฐ๋ผ์ ๋ ๋ฒ์งธ ๊ฒฝ๊ณ ์์๊ฐ ๋ซํ๋ ๊ฒ์ ๋ฐฉ์งํฉ๋๋ค. ๋ ๋ฒ์งธ swal ํธ์ถ์true
์ค์ ํ ์ ์์ต๋๋ค.