0

我想知道是否有人看过这个。我有一个剑道网格,在保存事件中,我想做一些验证。基本上要确保新值与旧值的差异小于或等于余额。

因此,如果它大于余额,我会触发警报并防止默认值。但是,显示警报会导致页面在 FireFox 中重新加载。

这是我的网格:

$("#gridOpenInvoices").kendoGrid({
        autoBind: false,
        dataSource: openInvoicesData,
        scrollable: true,
        sortable: false,
        navigatable: true,
        toolbar: [{name:"save",
                   text:strings.ApplyUpdates},
                  {name: "SplitPayment",
                   text: strings.SplitPayment},
                  {name: "PaidOut",
                   text: strings.PaidOut},
                  {name: "CreateCredit",
                   text: strings.CreditBalance},
                  {name: "UndoAllocation",
                   text: strings.UndoAllocation}],
        columns: [
            {
                field: "CustomerName",
                title: strings.AccountName,
                hidden: true
            },
            {
              field: "OpenTransactionId",
              title: strings.OpenTransaction,
              width:90
            },
            {
              field: "InvoiceNumber"  ,
              title: strings.InvoiceNumber,
              width:65
            },
            {
                field: "GrossSales",
                title: strings.OriginalAmount,
                width: 75,
                format: "{0:c}",
                decimals: 2,
                min: 1,
                value: 0

            },
            {
                field: "Balance",
                title: strings.TransBalance,
                width: 75,
                format: "{0:c}",
                decimals: 2,
                min: 1,
                value: 0

            },
            {
                field: "Date",
                title: strings.Date,
                width:75,
                format: "{0:MM/dd/yy}"

            },
            {
                field: "Age",
                title: strings.Age,
                width:55

            },
            {
                field: "CheckNumber",
                title: strings.CheckNumber,
                width:85
            },
            {
                title: strings.ApplyPayment,
                width:75,
                template: "<input class='k-chk-applied chkbox' type='checkbox' data-bind='source: IsApplied' name='IsApplied' #= IsApplied ? 'checked' : ''#/>",
                attributes:{"class":"tdIsApplied"}
            },
            {
                field:"AppliedAmount",
                title: strings.AppliedAmount,
                format: "{0:c}",
                width: 95,
                attributes: {"class" : "tdAppliedAmount"}
            }],
save: function(e) {
    var model = e.model;
    if (e.values.AppliedAmount != null) {
        var remainingBalance = context.getRemainingBalance();
        var difference = e.values.AppliedAmount - model.AppliedAmount;
        if (remainingBalance >= difference) {
            var balanceCopy = model.BalanceCopy;
            model.Balance = model.GrossSales - e.values.AppliedAmount;
            model.BalanceCopy = model.GrossSales - e.values.AppliedAmount;

            if (model.Balance == 0 && model.IsUncollected) {
                model.IsUncollected = false;
                context.UpdateBalance(balanceCopy, 0, true);
            }
            context.UpdateBalance(model.AppliedAmount, e.values.AppliedAmount, true);
            this.refresh();
            context.showButtons();
        } 
        else {
            alert("The applied amount exceeds the remaining balance");
            e.preventDefault();
        }
    }
}, editable:"incell"});

这似乎仅在您编辑应用金额并按 Enter 提交时才会发生。知道为什么会这样吗?

4

1 回答 1

0

解决方案相当简单:不要使用警报。

在 kendoUI Widgets 的某些事件中,我确实遇到了同样的问题。如果您需要向用户显示某些内容,请使用 kendoWindow 并将其 modal 属性设置为 true。

警报只能用于调试目的,例如 console.log。

于 2013-04-10T14:21:09.193 回答