0

我正在使用 jQuery UI 对话框来捕获数据并更新数据库。我想验证日期/时间字段以确保 scheduleStart(datetime) 不大于 scheduleStop (datetime)。

如果未满足验证,我想取消更新并在 UI 对话框上通知用户更改 css 样式。根据下面的代码,如何添加验证以检查我的日期框?

这是我的代码通过 .ajax 提交数据的样子:

$(document).ready(function(){

$(".openDialog").live("click", function (e) {
    e.preventDefault();
    $("<DIV></DIV>")
    .addClass("dialog")
    .attr("id", $(this).attr("data-dialog-id"))
    .appendTo("body")
    .dialog({
        title: $(this).attr("data-dialog-title"),
        width: dialogWidth,
        height: dialogHeight,
        close: function(){
            $(this).dialog("destroy");
            $(this).remove();
        },
        modal: true,
        cache: false,
        buttons: {
            "Save": function() {
                var recordId = $('#recordId').val();
                var scheduledStart = $('scheduledStart')convertToStandardDateTime($('scheduledStart').val());
                var scheduledStop = $('scheduledStop')convertToStandardDateTime($('scheduledStop').val());
                $.ajax({
                    type: "POST",
                    url: "@Url.action("SaveActivityDetails", "ActivtyDetails")",
                    Context: $(this),
                    Data: { recordId: recordId,
                            scheduledStart: (new Date(schededuledStart).toJSON(),
                            scheduledStop: (new Date(scheduledStop).toJSON() 
                          },
                    cache: false,
                    dataType: "json",
                    success: function () {
                        $this.html("");
                        $this.dialog("close");
                    },
                    error: function(xhr, textStatus, errorthrown)
                    {
                       //handle error
                    }
                });
             },
             "Cancel": function(){
                  $(this)dialog("close");
             }
          }
       })
       .load(this.href);
    });
});
4

0 回答 0