1
我一直在寻找使用敲除验证来比较日期的不同方法。我无法使用它在validatedObservable对象中使用我的obervables。敲除验证 - 日期大于其他日期
我需要validatedObservable来检查验证通过/失败的按钮单击 - 这是我的控件分组。
这里是我的演示:
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/knockout-2.3.0.js"></script>
<script src="~/Scripts/knockout.validation.min.js"></script>
<script src="~/Scripts/moment.min.js"></script>
<form>
<table>
<tr>
<td>Name:</td>
<td><input type="text" data-bind="value:contactForm().name" value="" /></td>
</tr>
<tr>
<td>From:</td>
<td><input type="text" data-bind="value:contactForm().fromDate" value="" /></td>
</tr>
<tr>
<td>To:</td>
<td><input type="text" data-bind="value:contactForm().toDate" /></td>
</tr>
</table>
<button type="button" data-bind='click: submit'>Submit</button>
</form>
<script>
ko.validation.init({
messagesOnModified: false,
parseInputAttributes: true,
grouping: {
deep: true
}
});
var myViewModel = function() {
var self = this;
self.contactForm = ko.validatedObservable({
name :ko.observable().extend({ required: true }),
fromDate :ko.observable('2014-11-10').extend({ date: true }),
toDate: ko.observable('2014-11-10').extend({date: true, min: this.fromDate })
});
submit = function() {
console.log(this.contactForm.isValid())
};
};
ko.applyBindings(new myViewModel());
</script>
我基本上不能获得这一行工作:
toDate: ko.observable('2014-11-10').extend({date: true, min: this.fromDate })
任何人任何想法?
感谢你为这个,是在好几个小时 – Frames84