I am trying to apply minimal theme of sweetalert2. But it is not working. This I put in the head -
<link href="/[email protected]/dist/sweetalert2.min.css" rel="stylesheet">
<link rel="stylesheet" href="/@sweetalert2/theme-minimal/minimal.css">
and this I put before the end of body tag -
<script src="/[email protected]/dist/sweetalert2.all.min.js"></script>
I used this code -
if (document.getElementById("fname").value == "") {
Swal.fire({
title: "Error!",
text: "Please enter your name!",
icon: "error",
theme: "minimal"
});
return false;
}
I want the alert to look smaller like this -
How do I achieve this?
I am trying to apply minimal theme of sweetalert2. But it is not working. This I put in the head -
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-minimal/minimal.css">
and this I put before the end of body tag -
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/sweetalert2.all.min.js"></script>
I used this code -
if (document.getElementById("fname").value == "") {
Swal.fire({
title: "Error!",
text: "Please enter your name!",
icon: "error",
theme: "minimal"
});
return false;
}
I want the alert to look smaller like this -
How do I achieve this?
There is no theme
option on fire
.
You just need to import the minimal theme css and the javascript itself:
Swal.fire({
title: "Success!",
text: "Record added/updated successfully.",
icon: "success",
width: '350px' // Custom width
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-minimal/minimal.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js"></script>
You can define a customClass
in sweet alert to add style in dialog and make it smaller as shown here.
//This is default Sweet Alert Dialog
document.getElementById("defaultAlert").addEventListener("click", function() {
if (document.getElementById("fname").value == "") {
Swal.fire({
title: "Error!",
text: "Please enter your name!",
icon: "error",
theme: "minimal"
});
return false;
}
});
//After adding custom class
document.getElementById("withCustomStyle").addEventListener("click", function() {
if (document.getElementById("fname").value == "") {
Swal.fire({
title: "Error!",
text: "Please enter your name!",
icon: "error",
customClass: 'customDialog'
});
return false;
}
});
.customDialog{
font-size:8px !important;
width:250px !important;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-minimal/minimal.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js"></script>
<input type="text" id="fname" placeholder="Enter your name">
<button id="defaultAlert">Default Alert</button>
<button id="withCustomStyle">Custom Alert</button>