function saveDefect() {
swal({
title: "Do you want to save it?",
text: "Please check Information before Submiting!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Save",
cancelButtonText: "Cancel",
closeOnConfirm: false,
closeOnCancel: false
}).then(
function (isConfirm) {
if (isConfirm) {
var defect = new Object();
defect.ProductDefectId = $("#defectId").val();
defect.CategoryId = $("#categoryId").val();
defect.Date = $("#date1").val();
defect.Product = $("#product").val();
defect.Qty = $("#quantity").val();
defect.Price = $("#price").val();
defect.Total = $("#total_1").val();
defect.Remarks = $("#remark").val();
var data = JSON.stringify({
defect: defect
});
}
});
return $.ajax({
contentType: 'application/json; charset=ut-8',
dataType: 'json',
type: 'POST',
url: "/Home/SaveDefect",
data: data,
success: function (result) {
if (result == true) {
GetAllDefectProduct();
swal("1 Defective Product Save Successfully")
}
else {
swal("Cancelled", "You have Cancelled Form Submission!", "error");
}
}
});
}
function GetAllCategory()
{
$.ajax({
contentType: "application/json; charset=ut-8",
datatype: "json",
type: "Get",
url: "/Home/GetAllCategory",
success: function (data) {
$("#categoryId").html('');
var tdContent = '';
for (var i = 0; i < data.length; i++) {
tdContent += '';
}
$("#categoryId").append(tdContent);
},
error: function () {
alert("Error!")
}
})
}Loading
Vishal JoshiPosted Mar 20, 2023, 6:06 AM
Hello
The issue looks in your javascript code is not synced. it looks like you have used some other framework along with javascript.
if you are using Angular or React with javascript then you need to synch or compile javascript code once the angular js controller initialized.
Also, check sweetalert.min.js reference added and reflective to a specific page.
Thanks
Emmmanuel FIADUFEPosted Mar 17, 2023, 2:38 PM
Everything is now working as i expected, and this is how I re-write the code.
function saveDefect() {
var defect = new Object();
defect.ProductDefectId = $("#defectId").val();
defect.CategoryId = $("#categoryId").val();
defect.Date = $("#date1").val();
defect.Product = $("#product").val();
defect.Qty = $("#quantity").val();
defect.Price = $("#price").val();
defect.Total = $("#total_1").val();
defect.Remarks = $("#remark").val();
var data = JSON.stringify({
defect: defect
});
swal("Save!", "Defective Product added successfully", "success");
$("#success-message").click(function (e) {
Swal.fire({
title: "Good job!",
text: "You clicked the button!",
icon: "success",
buttonsStyling: false,
confirmButtonText: "Confirm me!",
customClass: {
confirmButton: "btn btn-primary"
}
});
});
return $.ajax({
contentType: 'application/json; charset=ut-8',
dataType: 'json',
type: 'POST',
url: "/Home/SaveDefect",
data: data,
success: function (result) {
if (result == true) {
Reset();
GetAllDefectProduct();
$("#ProductDefectModal").modal('hide');
}
}
});
}
Emmmanuel FIADUFEPosted Mar 3, 2023, 7:20 PM
I re-arrange the code this way and it work for me, but what I want now is instead of the sweetalert giving me a mark success after saving the data, it rather gives me a popup, Sachin I tried your format too but it it gives me a popup.
function saveDefect() {
var defect = new Object();
defect.ProductDefectId = $("#defectId").val();
defect.CategoryId = $("#categoryId").val();
defect.Date = $("#date1").val();
defect.Product = $("#product").val();
defect.Qty = $("#quantity").val();
defect.Price = $("#price").val();
defect.Total = $("#total_1").val();
defect.Remarks = $("#remark").val();
var data = JSON.stringify({
defect: defect
});
swal({
title: "Do you want to save this product?",
text: "Please check Information before Submiting!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#4BB543",
confirmButtonText: "Save",
cancelButtonText: "Cancel",
closeOnConfirm: false,
closeOnCancel: false
}).then( function (isConfirm) {
if (isConfirm) {
return $.ajax({
contentType: 'application/json; charset=ut-8',
dataType: 'json',
type: 'POST',
url: "/Home/SaveDefect",
data: data,
success: function (result) {
if (result == true) {
Reset();
GetAllDefectProduct();
$("#ProductDefectModal").modal('hide');
swal( " 1 Defective Product Save Successfully!")
}
}
});
} else {
$("#ProductDefectModal").modal('hide');
swal("Cancelled", "You have Cancelled Form Submission!", "error");
}
});
}
Emmmanuel FIADUFEPosted Mar 3, 2023, 6:54 PM
Hello Sachin, I tried your format as you said and it only brings the sweetalert popup without saving the data
Sachin SinghPosted Mar 3, 2023, 3:23 PM
test this
Emmmanuel FIADUFEPosted Mar 3, 2023, 10:12 AM
Thank you guys, the modal popup is coming this time round but the confirmation buttons that is responsible for save or cancel before action is perform is not showing, kindly assist.
Naimish MakwanaPosted Mar 3, 2023, 4:36 AM
It seems that the code is missing the necessary reference to the sweet alert library. You need to include the sweet alert library in your HTML file using a script tag before the script that calls the swal function in the saveDefect function.
Add below code to your HTML file inside the head tag or before the script that calls the swal function in the saveDefect function.
Thanks
Tuhin PaulPosted Mar 2, 2023, 6:55 PM
Check that the sweet-alert.js file is properly included in your HTML page where the saveDefect() function is being called.
You can include the sweet-alert.js file in the head section of your HTML page as follows:
Once the sweet-alert.js file is properly included, the swal function should be defined and you should be able to use it in the saveDefect() function.
Sachin SinghPosted Mar 2, 2023, 3:21 PM
you need to add sweetalert cdn or local downladed link inside your html or cshtml or aspx page whatever it is.