Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate field in observablearray not working (using knockout validation plugin)
    text
    copied!<p>I am using the knockout validation plug in and am trying to compare a date field in the observablearray to a static date. I know the code is not complete, but here is what i have-</p> <p>EDIT: VIEW CODE-</p> <pre><code> &lt;tbody data-bind="foreach: allCertificates"&gt; &lt;tr id="AllCertRow" style="cursor: pointer" data-bind="click: $parent.selectThing, css: { highlight: $parent.isSelected() == $data.lwCertID }"&gt; &lt;td&gt; &lt;ul &gt; &lt;li&gt;&lt;H5&gt;&lt;b&gt;&lt;span data-bind=" text: clientName"&gt;&lt;/span&gt;&amp;nbsp;(&lt;span data-bind=" text: clientNumber"&gt;&lt;/span&gt;)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span data-bind=" text: borrowBaseCount"&gt;&lt;/span&gt;&amp;nbsp;Loan(s)&amp;nbsp;&lt;/b&gt;&lt;/H5&gt;&lt;/li&gt; Collateral Analyst:&amp;nbsp;&lt;span data-bind=" text: userName"&gt;&lt;/span&gt; &lt;br /&gt; Certificate:&amp;nbsp;&lt;span data-bind="text: lwCertID"&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;Request&amp;nbsp;Date:&amp;nbsp;&lt;span data-bind=" text: moment(requestDate).format('DD/MMM/YYYY')"&gt;&lt;/span&gt; &lt;/ul&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; </code></pre> <p>My viewmodel code-</p> <pre><code> var LucasSystemDate = ko.observableArray('4/22/2013'); var allCertificates = ko.observableArray([]); ko.validation.configure({ registerExtenders: true, messagesOnModified: true, insertMessages: true, parseInputAttributes: true, messageTemplate: null, grouping: { deep: true } }); ko.validation.rules['Expired'] = { validator: function (val, otherVal) { return val &lt; otherVal; }, message: 'Request has expired. Please reject and initiate client contact.' }; var activate = function () { // go get local data, if we have it return true; }; var vm = { activate: activate, LucasSystemDate: LucasSystemDate, allCertificates: allCertificates[ { lwCertID: '2', clientID: '1EX', requestDate: '7/3/2013 12:34:00 PM', userName: 'Peter Rabbit', statusDescription: 'Submitted', statusCode: '1', statusDesc: 'Submitted', clientName: 'Test Company 1 ', clientNumber: '1EX', borrowBaseCount: '1', advRequestCount: '1', ceoUserName: 'Woodall, Chris' }, { lwCertID: '5', clientID: '1EX ', requestDate: '7/3/2013 1:00:00 PM', userName: 'Bugs Bunny', statusDescription: 'Submitted', statusCode: '1', statusDesc: 'Submitted', clientName: 'Test Company 2 ', clientNumber: '1EX', borrowBaseCount: '1', advRequestCount: '1', ceoUserName: 'Woodall, Chris' }, { lwCertID: '6', clientID: '1EX ', requestDate: '7/8/2013 6:31:00 AM', userName: 'Jack Frost', statusDescription: 'Submitted', statusCode: '1', statusDesc: 'Submitted', clientName: 'Test Company 3 ', clientNumber: '1EX', borrowBaseCount: '1', advRequestCount: '1', ceoUserName: 'Woodall, Chris' } ] } //NOT SURE HOW TO COMPARE requestDate IN THE allCertificates OBSERVEABLEARRAY TO //THE LucasSystemDate. IF LucasSystemDate &lt; allCertificates.requestDate //THEN FAIL VALIDATION AND DISPLAY ERROR MESSAGE. THIS CHECK SHOULD //BE PERFORMED EACH TIME THE DATA IS INITIALLY LOADED. </code></pre> <p>Under the commented out code at the bottom of the code above, what code would I put here to use the Expired validation rule to compare the requestDate in the allCertificates observablearray to the LucasSystemDate? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload