淘汰赛 - 验证组没有约束力

时间:2014-02-10 18:39:10

标签: javascript html validation knockout.js knockout-validation

我有一个验证组,用于捕获包含联系人对象的客户对象的错误。联系对象中有4个必填字段。有时,当我为联系人填写这些必填字段时,错误将保留在customerErrors验证组中。我已经介入并检查了联系人的每个属性,以确保值存在,并且我已经检查了他们的isValid()属性,并且它们都是真的。我在视图中声明这些变量的扩展名如下:

<div class="right-column" style="width:45%;" data-bind="with: ContactsDTO()[0]">
    <h6>Contact</h6>
    <label class="required">First Name<input type="text" class="k-textbox big-textbox" data-bind="value: FirstName.extend({ required: { message: 'First Name is a required field.', params: true } })"></label>
    <label class="required">Last Name<input type="text" class="k-textbox big-textbox" data-bind="value: LastName.extend({ required: { message: 'Last Name is a required field.', params: true } })"></label>
    <label class="required">Email<input type="text" class="k-textbox big-textbox" data-bind="value: Email.extend({ required: { message: 'Email is a required field.', params: true } })"></label>
    <label class="required">Business Phone<input type="text" class="k-textbox big-textbox" data-bind="value: BusinessPhone.extend({ required: { message: 'Phone is a required field.', params: true } })"></label>
</div>

我正在初始化viewModel上的验证,如下所示:

self.estimateErrors = ko.validation.group(self.estimate());
self.customerErrors = ko.validation.group(self.estimate().CustomerDTO(), { deep: true });
self.workOrderErrors = ko.validation.group(self.estimate().WorkOrdersDTO(), { deep: true });
self.estimateSalesRepErrors = ko.validation.group(self.estimate().EstimateSalesRepsDTO(), { deep: true });
self.estimateScopeServiceErrors = ko.validation.group(self.estimate().EstimateScopeServicesDTO(), { deep: true });
ko.validation.init({ insertMessages: false, errorsAsTitle: false, decorateElement: true, errorElementClass: 'error', parseInputAttributes: true });

我还没能找到有类似问题的人,所以任何帮助都会很棒。

0 个答案:

没有答案