knockout.js - knockout js ensuring one value is larger than another -


i have following business requirement:

there 2 textboxes user needs input current age , retirement age. retirement age needs greater current age if user inputs retirement age that's less current age should update retirement age current age, , if user inputs current age greater retirement age retirement age must set current age.

is there easy way using knockout js? i'm assuming i'll need computed observable both fields kind of backing store?

heres starting point: http://jsfiddle.net/rvnhy/

js:

var viewmodel = function() {     this.currentage= ko.observable(32);     this.retirementage = ko.observable(44);   };  ko.applybindings(new viewmodel ()); 

html:

<div class='liveexample'>        <p>current age: <input data-bind='value: currentage' /></p>      <p>retirement age: <input data-bind='value: retirementage' /></p>  </div> 

yeah, want:

function myviewmodel() {     var self = this;     var age= ko.observable(32);     var retage = ko.observable(44);       self.currentage = ko.computed({         read: function () {             return age();         },         write: function (value) {             retage(math.max(value, retage));             age(value);         },         owner:     }); } 

and same create computed observable retirement age.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -