λ¬Έμμμ λλ½λ κ²μ΄ μλ ν μ λ ₯ νλμ κ²°ν©λ λ€λ₯Έ κ°μ κ°μ§ μ¬λ¬ λ²νΌμ΄ μλ swalμ λ§λ€λ©΄ μ λ ₯ κ°μ΄ κΈ°λ³Έ swal μ½λλ₯Ό μ¬μ©νμ¬ λ°νλμ§ μλλ€λ κ²μ΄ μ΄λ¦¬μμ μΌμ λλ€. μ΄κ²μ μ€μ λ‘ SweetAlertκ° μ 곡ν΄μΌ νλ μ μ¬μ κ°λ₯μ±μ μμ μ€λλ€.
νμΈ λ²νΌκ³Ό λ€λ₯Έ λ²νΌμ΄ λͺ¨λ μ λ ₯ κ°μ λ°ννκΈ°λ₯Ό μνμλκΉ? μ¬μ© μ¬λ‘κ° μ νν 무μμΈμ§ μμΈν μ€λͺ ν΄ μ£Όμκ² μ΅λκΉ? :)
@t4t5 μλ§λ μ΄ FIXME μ κ΄λ ¨ .
swal({
buttons: {
cancel: "Go back!",
one: {
text: "Button One",
value: 1
},
two: {
text: "Button Two",
value: 2
},
three: {
text: "Button Three",
value: 3
}
},
content: {
element: "input",
attributes: {
placeholder: "What's your favorite food?",
type: "text",
},
}
/*
* Only returns one value, because input is overridden by buttons
* so you never get the input's value and the button's value
* just the button's value.
*/
}).then( value => {
switch (value) {
case 1:
swal("You pressed one!")
break;
case 2:
swal("You pressed two!")
break;
case 3:
swal("You pressed three!")
break;
default:
swal("Phew, got outta there.");
}
});
λ²νΌ κ°μ μ¬μ©ν μ μλ κΈ°λ₯κ³Ό μ λ ₯ κ°μ΄ 무μμ΄λ κ°μ μ€μ²© κ²½κ³ λμ λ Όλ¦¬λ₯Ό μννκ³ λ²νΌμ μν΄ μ¬μ μλκΈ° λλ¬Έμ μΈλͺ¨μλ μ λ ₯μ΄ μμΌλ©΄ λ§€μ° μ μ©ν©λλ€.
button
κ°κ³Ό content
κ°μ λͺ¨λ ν¬ν¨νλ €λ©΄ +1
λ²νΌμ ν€ μ€ νλλ₯Ό "νμΈ"μΌλ‘ μ€μ νλ©΄ μ λ ₯ κ°μ΄ λ°νλ©λλ€. μ:
swal({
buttons: {
cancel: "Go back!",
one: {
text: "Button One",
value: 1
},
two: {
text: "Button Two",
value: 2
},
confirm: {
text: "Button Three",
}
},
content: {
element: "input",
attributes: {
placeholder: "What's your favorite food?",
type: "text",
},
}
})
μ¬μ© μ¬λ‘μ μΆ©λΆν©λκΉ, μλλ©΄ λͺ¨λ λ²νΌμ΄ μ λ ₯ κ°κ³Ό λ²νΌ κ°μ λͺ¨λ λ°νν΄μΌ νλ€λ μλ―Έμ λκΉ?
@t4t5 λͺ¨λ λ²νΌμ μ λ ₯ κ°κ³Ό λ²νΌ κ°μ λ°νν΄μΌ ν©λλ€. νΉν λ΄ μ¬μ© μ¬λ‘μ κ²½μ° μΉ κΈ°λ° μλ² κ΄λ¦¬ λꡬμ SweetAlertλ₯Ό μ¬μ©νκ³ μμΌλ©° λ³΄λ€ κ΅¬μ²΄μ μΌλ‘λ μ¬μ©μκ° "κΈμ§" λ²νΌμ ν΄λ¦ν λ κ΄λ¦¬μμκ² ν둬ννΈλ₯Ό νμν©λλ€. κ·Έλ° λ€μ κ²½κ³ μλ μκ° κΈΈμ΄λ₯Ό λνλ΄κΈ° μν΄ ("1d", "1w" λλ "forever") κ°μ λ°νν΄μΌ νλ μΈ κ°μ λ²νΌμ΄ μμ΅λλ€. λν μ¬μ©μκ° κΈμ§λ μ΄μ μ λν μ΄μ λ₯Ό μ 곡νκΈ° μν΄ μ λ ₯ ν μ€νΈ νλκ° νμν©λλ€. μ΄ λ²νΌ μ€ νλλ₯Ό ν΄λ¦νλ©΄ λ΄ μ½λ°±μ΄ ν΄λ¦ν λ²νΌμ κ°κ³Ό μ λ ₯ κ°μ μμΌλ‘ λ§λ€μ΄ λ΄ μλ²μ API 쿼리λ₯Ό μμ±νμ¬ μ°¨λ¨ μ΄μ μ μ°¨λ¨ κΈ°κ°μ μ€μ ν μ μμ΅λλ€.
μ΄ μ¬μ© μ¬λ‘κ° λ κ°μ λͺ¨λ λ°ννλ κ²μ μ€μμ±μ λͺ νν νκΈ°λ₯Ό λ°λλλ€. μ΄λ₯Ό ν΅ν΄ κ°λ°μλ 1λ¨κ³ νλ‘μΈμ€μ¬μΌ νλ μμ μ μννκΈ° μν΄ μ¬λ¬Όμ ν΄νΉνκ±°λ λ κ°μ κ²½κ³ λ₯Ό μμ±ν νμκ° μμ΅λλ€.
banPlayer: function (data) {
var swalField = document.createElement('input');
swalField.setAttribute("placeholder", "Reason for ban");
swal({
title: 'Banning: ' + data.name,
buttons: {
cancel: "Go back!",
day: {
text: "24hr",
visible: true,
closeModal: true
},
week: {
text: "1w",
visible: true,
closeModal: true
},
perm: {
text: "Forever",
visible: true,
closeModal: true
}
},
content: swalField,
dangerMode: true
}).then( value => {
let reason = swalField.value;
// build API query request and submit it
});
μμ μ€λν«μ μ½ν μΈ μ λ²νΌ κ°μ κ°μ Έμ€λ "ν΄ν€" λ°©μμ λλ€. κ·Έλ¬λ μ΄ μ€λ λμ μλΆλΆμμ ννν κ²μ²λΌ λ κ°μ λͺ¨λ λ°ννλλ‘ νλ κ²μ΄ ν¨μ¬ μ’μ΅λλ€.
λ λ€λ₯Έ μλ μ
λ ₯ νλμ λ κ°μ λ²νΌμΈ νμΈ + μ·¨μκ° μλ λͺ¨λ¬( closeOnEsc: false, closeOnClickOutside: false
)μ
λλ€. μ§κΈμ @JayHerlth μ루μ
μ μ¬μ©
κ°μ₯ μ μ©ν λκΈ
@t4t5 λͺ¨λ λ²νΌμ μ λ ₯ κ°κ³Ό λ²νΌ κ°μ λ°νν΄μΌ ν©λλ€. νΉν λ΄ μ¬μ© μ¬λ‘μ κ²½μ° μΉ κΈ°λ° μλ² κ΄λ¦¬ λꡬμ SweetAlertλ₯Ό μ¬μ©νκ³ μμΌλ©° λ³΄λ€ κ΅¬μ²΄μ μΌλ‘λ μ¬μ©μκ° "κΈμ§" λ²νΌμ ν΄λ¦ν λ κ΄λ¦¬μμκ² ν둬ννΈλ₯Ό νμν©λλ€. κ·Έλ° λ€μ κ²½κ³ μλ μκ° κΈΈμ΄λ₯Ό λνλ΄κΈ° μν΄ ("1d", "1w" λλ "forever") κ°μ λ°νν΄μΌ νλ μΈ κ°μ λ²νΌμ΄ μμ΅λλ€. λν μ¬μ©μκ° κΈμ§λ μ΄μ μ λν μ΄μ λ₯Ό μ 곡νκΈ° μν΄ μ λ ₯ ν μ€νΈ νλκ° νμν©λλ€. μ΄ λ²νΌ μ€ νλλ₯Ό ν΄λ¦νλ©΄ λ΄ μ½λ°±μ΄ ν΄λ¦ν λ²νΌμ κ°κ³Ό μ λ ₯ κ°μ μμΌλ‘ λ§λ€μ΄ λ΄ μλ²μ API 쿼리λ₯Ό μμ±νμ¬ μ°¨λ¨ μ΄μ μ μ°¨λ¨ κΈ°κ°μ μ€μ ν μ μμ΅λλ€.
μ΄ μ¬μ© μ¬λ‘κ° λ κ°μ λͺ¨λ λ°ννλ κ²μ μ€μμ±μ λͺ νν νκΈ°λ₯Ό λ°λλλ€. μ΄λ₯Ό ν΅ν΄ κ°λ°μλ 1λ¨κ³ νλ‘μΈμ€μ¬μΌ νλ μμ μ μννκΈ° μν΄ μ¬λ¬Όμ ν΄νΉνκ±°λ λ κ°μ κ²½κ³ λ₯Ό μμ±ν νμκ° μμ΅λλ€.
μμ μ€λν«μ μ½ν μΈ μ λ²νΌ κ°μ κ°μ Έμ€λ "ν΄ν€" λ°©μμ λλ€. κ·Έλ¬λ μ΄ μ€λ λμ μλΆλΆμμ ννν κ²μ²λΌ λ κ°μ λͺ¨λ λ°ννλλ‘ νλ κ²μ΄ ν¨μ¬ μ’μ΅λλ€.