弹出警告消息后,添加按钮上的问题变为禁用状态

时间:2013-09-24 09:03:20

标签: javascript jquery html asp.net-mvc-3 kendo-grid

我的添加按钮有问题...我想要一个条件,如果网格中有相同的数据,如果添加按钮单击,则会弹出警告消息。但它会在弹出警报消息后发生,添加按钮将被禁用。我坚持这个问题好几天了。感谢有帮助的人。

HTML:

<div class="main">
        @using (Html.BeginForm("AvailabilitySave", "Worker", FormMethod.Post, new { id = "AvailabilityForm" }))

        {

            <input type="hidden" id="availabilityId" name="workerId" value="@workerId" />

          <p>
                    <label for="dllAvailableDay">
                        <abbr title="This is a required field.">
                            <em><font color="red">*</font></em></abbr>
                        Available Day</label>
                    <span>
                        @Html.DropDownList("dllAvailableDay", new SelectList(ViewBag.availableDayList, "ID", "Display_Value", workerAvailableDay), "[Please Select]",
              new Dictionary<string, object>
                    {
                        {"class","validate[required] inputLong"}
                    })
                    </span>
                </p>
                <p>
                    <label for="TpStartTime">
                        <abbr title="This is a required field.">
                            <em><font color="red">*</font></em></abbr>
                        Start Time</label>
                    <span>
                        <input id="tpStartTime" name ="tpStartTime" value="@workerStartTime" 
                               style="padding:0 0 0 0 !important" />
                    </span>
                </p>

                <p>
                    <label for="TpEndTime">
                        <abbr title="This is a required field.">
                            <em><font color="red">*</font></em></abbr>
                        End Time</label>
                    <span>
                        <input id="tpEndTime" name ="tpEndTime" value="@workerEndTime" 
                                style="padding:0 0 0 0 !important"/>
                    </span>
                  </p>
    <p>
                    <label>
                        Anytime</label>
                    <span>
                        <input type="checkbox" name="chAnytime" id="chAnytime" value="true" checked="checked" />
                    </span>
                </p>
                <p>
                    <span>
                        <input type="submit" id="addAvailBtn" class="styledButton" value="Add" />
                    </span>
                </p>
}
</div>

JS:

$("#AvailabilityForm").on('submit', function (e) {

        var gvDetDDLs = $('#availabilityGrid').find("input[name=dllEditAvailableDay]");
        $.each(gvDetDDLs, function () {
            var duplicateExists = false;
            var ddlDay = $("#dllAvailableDay option:selected").text();
            var currVal = $(this).val();

            gvDetDDLs.not(this).each(function () {
                e.preventDefault();
                if (ddlDay == currVal) {
                    duplicateExists = true;
                    $(this).focus();
                    return false;
                }

            });
            if (duplicateExists) {
                alert("Duplicate entry is not allowed");
                return false;
                $('#addAvailBtn').prop('disabled', false);
            }

        });
        return true;
    });

格:

$("#availabilityGrid").kendoGrid({
        scrollable: false,
        sortable: true,
        pageable: true,
        dataSource: {
            transport: {
                read: {
                    url: '/Worker/GetAvailabilityList?availabilityId=' + availabilityId,
                    dataType: "json",
                    type: "POST"
                }
            },
            change: function (e) {
                $(window.location.hash).click();
            },
            pageSize: 10
        },
        rowTemplate: kendo.template($("#availabilityTemplate").html().replace('k-alt', '')),
        altRowTemplate: kendo.template($("#availabilityTemplate").html())
    });

控制器:

private void GetAvailableDayList()
        {
            var availableDayList = (from a in db.Lookups
                                    where a.Domain == "AVAILABLEDAY"
                                    select a).ToList();

            ViewBag.AvailableDayList = availableDayList;
        }

0 个答案:

没有答案