This question is locked. New answers and comments are not allowed.
Greetings,
I'm having some strange behavior with the the OnSave e.preventDefault() event firing correctly when inside an ajax call in my Grid editor. Here's the code snippet for the call:
function onSave(e) {
var masterRow = $(e.form).closest('.t-detail-row').prev();
var parentDataItem = masterRow.closest('.t-grid').data('tGrid').dataItem(masterRow);
var mode = e.mode;
var grid = $(this).data('tGrid');
var values = e.values;
//Grab the parent record visinumber to be used in the ajax call below
var parentVisitNumber = parentDataItem['VisitNumber'];
var chData = true;
$.ajax({
type: "POST",
url: "<%= ResolveUrl("~/TradingPost/GetSingleCamperRowRecord") %>",
data: "visitNumber=" + parentVisitNumber,
success: function (result) {
var depositItem = result.CamperTPDeposit;
var spentItem = result.CamperTPTotal;
var balanceItem = result.CamperTPRemainingBalance;
if (spentItem == null){
spentItem = "0"
}
if(values.Amount > balanceItem)
{
chData = false;
alert("The amount you are trying to submit is greater than the available balance.");
e.preventDefault();
}
},
error: function (req, status, error) {
alert("Error occured.");
}
});
....
Two odd things are happening: 1.) The value of chData does not change. If I check it's value outside the ajax() call, it is still true, even though it has been set to false in the ajax code. 2.) If I have any type of alert() message popup at the end/outside the ajax call, the e.preventDefault() fires correctly. I'm sure I'm missing something in relation to how ajax results work with the preventDefault() functionality. Any help would be most appreciated.
Thank you!
Scott
I'm having some strange behavior with the the OnSave e.preventDefault() event firing correctly when inside an ajax call in my Grid editor. Here's the code snippet for the call:
function onSave(e) {
var masterRow = $(e.form).closest('.t-detail-row').prev();
var parentDataItem = masterRow.closest('.t-grid').data('tGrid').dataItem(masterRow);
var mode = e.mode;
var grid = $(this).data('tGrid');
var values = e.values;
//Grab the parent record visinumber to be used in the ajax call below
var parentVisitNumber = parentDataItem['VisitNumber'];
var chData = true;
$.ajax({
type: "POST",
url: "<%= ResolveUrl("~/TradingPost/GetSingleCamperRowRecord") %>",
data: "visitNumber=" + parentVisitNumber,
success: function (result) {
var depositItem = result.CamperTPDeposit;
var spentItem = result.CamperTPTotal;
var balanceItem = result.CamperTPRemainingBalance;
if (spentItem == null){
spentItem = "0"
}
if(values.Amount > balanceItem)
{
chData = false;
alert("The amount you are trying to submit is greater than the available balance.");
e.preventDefault();
}
},
error: function (req, status, error) {
alert("Error occured.");
}
});
....
Two odd things are happening: 1.) The value of chData does not change. If I check it's value outside the ajax() call, it is still true, even though it has been set to false in the ajax code. 2.) If I have any type of alert() message popup at the end/outside the ajax call, the e.preventDefault() fires correctly. I'm sure I'm missing something in relation to how ajax results work with the preventDefault() functionality. Any help would be most appreciated.
Thank you!
Scott