knockout.js - Where to trigger application of bindings -


in durandal app have dialog containing view bound viewmodel.

the label elements each of input elements includes warning glyph done icon-warning-sign. visibility of each glyph controlled data-binding this:

<div class="form-group">   <label for="email">     email <i class="icon-warning-sign orange"        data-bind="visible:email.haserror, attr: { title:email.validationmessage }"></i>   </label>   <input id="email" class="form-control" type="text"      data-bind="value: email, valueupdate: 'afterkeydown'" /> </div> 

email observable property of view model. haserror property sub-observable created extender. there several of these, here's sample. validate implementation varies.

function prepforextender(target) {   if (target.haserror) return;   target.haserror = ko.observable();   target.validationmessage = ko.observable(); }  ko.extenders.required = function (target, overridemessage) {    prepforextender(target);    //define function validation   function validate(newvalue) {     target.haserror(!newvalue);     target.validationmessage(newvalue ? "" :        overridemessage || "this field required");   }    //initial validation   validate(target());    //validate whenever value changes   target.subscribe(validate);    //return original observable   return target; }; 

here's sample use of extender.

register.firstname = ko.observable()   .extend({ required: "first name missing" }); 

it works fine except ie8. no titters ie8 peanut gallery please, it's client's soe , that's there it. in ie8 when dialog opens warning glyphs not visible. if edit input's value glyph's visibility correctly updated, bindings , logic work ok.

how can trigger evaluation when dialog first displayed?

more info: glyphs don't become visible until there transition haserror() == true. if page starts haserror true given input have cause haserror return false , true again in order cause glyph become visible.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -