我在页面上有这个标记:
<div data-bind="visible: found">
<div data-bind="with: eventDetails">
<!-- Some stuff -->
</div>
<div style="clear: left">
<div id="newShow" title="Add a Show"></div>
<a href="#" class="btn btn-primary" id="addShow" data-bind="click: addShow">Add a Show</a> <!-- this is bound to a knockout viewmodel which calls addShowDialog() function -->
</div>
</div>
这是加载到的表格div#newShow
<form action="/MyEvents/AddShow/events-385" id="addShowForm" method="post" novalidate="novalidate"> <div>
<div class="editor-label">
<label for="Name">Name</label>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-required="The Name field is required." id="Name" name="Name" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="Date">Date</label>
</div>
<div class="editor-field">
<input class="text-box single-line hasDatepicker" data-val="true" data-val-date="The field Date must be a date." data-val-required="The Date field is required." id="Date" name="Date" type="datetime" value="10 January 2013">
<span class="field-validation-valid" data-valmsg-for="Date" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="ReportingTime">ReportingTime</label>
</div>
<div class="editor-field">
<input class="text-box single-line hasDatepicker" data-val="true" data-val-date="The field ReportingTime must be a date." data-val-required="The ReportingTime field is required." id="ReportingTime" name="ReportingTime" type="datetime" value="03:26 p.m.">
<span class="field-validation-valid" data-valmsg-for="ReportingTime" data-valmsg-replace="true"></span>
</div>
<div class="editor-label">
<label for="JudgingStarts">JudgingStarts</label>
</div>
<div class="editor-field">
<input class="text-box single-line hasDatepicker" data-val="true" data-val-date="The field JudgingStarts must be a date." data-val-required="The JudgingStarts field is required." id="JudgingStarts" name="JudgingStarts" type="datetime" value="03:26 p.m.">
<span class="field-validation-valid" data-valmsg-for="JudgingStarts" data-valmsg-replace="true"></span>
</div>
</div>
</form>
这是插入表单并处理从表单返回的 Javascript:
function addShowDialog() {
$.get('/myevents/addShow/' + eventId,
null,
function (data, textStatus, xhr) {
refreshTarget($('#newShow'), data);
$('#newShow').dialog('open');
});
};
$('#newShow').dialog({
autoOpen: false,
modal: true,
resizable: false,
buttons: {
"Create a Show": function () {
var form = $('#addShowForm');
var valid = form.valid(); //<-- this always returns true!
if (valid) {
var formData = form.serialize();
formData = formData + '&EventId=' + encodeURIComponent(eventId);
$.post(
form.attr('action'),
formData,
function(data) {
if (data == "Success") {
$('#newShow').dialog("close");
}
}
);
}
},
"Cancel": function () {
$(this).dialog("close");
}
},
close: function () {
loadData();
}
});
我无法输入表格div#newShow
进行验证。检查form.valid()
总是返回真。我的头(和眼球)有点像整个事情一样游泳,所以我希望这是有道理的。
请问有什么想法吗?