0

I am new to KnockoutJS and I am having some trouble with validation. I have two textboxes and I am trying to validate to ensure that textbox1 input value is greater than textbox2 input value.

<input type="number" id="tbLow" name="tbLow" data-bind="value: model.tbLow"/>
<input type="number" id="tbHigh" name="tbHigh" data-bind="value: model.tbHigh"/>

this isthe validation for tbLow:

self.model.tbLow.extend({
    min: 1,
    max: 999999,
    maxLength: 6,
    validation: { validator: greaterThan, 
                  message: 'tbHigh must be larger than Car tbLow.', 
                  params: tbHigh }

});

here is the validation function:

var greaterThan = function (tbLow, tbHigh ) {
    return CarNumberHigh > CarNumberLow;
}

I am not able to get the value for tbHigh... Any ideas??

4

1 回答 1

0

An extender wraps an observable. Are you setting the value of model.tbLow to the result of the observable.extend() function?

Your code should look like this:

self.model.tbLow = self.model.tbLow.extend({ ... });

Or if you extend it from within your model...

this.tbLow = ko.observable(...).extend({ ... });

Did you write that validation extender yourself or are you using something you found? Can you post or link to the code for that? Otherwise we don't know if you're using it properly, we can't know what the 'greaterThan' function is being sent.

于 2013-08-16T16:25:01.217 回答