knockout.js - knockout validation messages not showing up -
knockout.js - knockout validation messages not showing up -
i've been working model single page app while , 1 little issue crops time time inconsistent error messages showing validated fields.
jsfiddle example
if play box below line on illustration before touching of links above, find works expect. but, 1 time start clicking on links edit, or add together new record, validation messages stop displaying. validation model still works though (as evidenced message i've hard coded below edit form text input).
i guess i'm asking, what's deal? bug validation? result of way structuring type of page?
summary of design can sense design choices here - set object (called pm) , attach bunch of elements it. 1 of elements edit observable phone call pm.item. i'm taking approach because lot of pages design load list of records people want able edit. rather having them edit record straight require maintain track of state , reset it, pass info list item edit item way of edit item template (called pm.itemtemplate in code). handy approach allows me create , editing object. guess validation breaks up.
pm.itemtemplate = function (data) { var obj = { title: ko.observable(""), id: ko.observable(0) }; if (data) { obj.title(data.title); obj.id(data.id); } obj.err = ko.validatedobservable({ titleproperty: obj.title.extend({ required: true }) }); homecoming obj; };
one other of import thing notice, validation still works - messages stop showing up. logic in save function totally supposed do.
pm.saveitem = function () { if (pm.item().err.isvalid()) { if (pm.item().id() == 0) { //this new 1 pm.list.push({ title: pm.item().title(), id: pm.list().length }) } else { //normally server side work update record , fetch new version, //example i'm overwriting row var current = _.findwhere(pm.list(), { id: pm.item().id() }); current.title = pm.item().title(); pm.list(ko.tojs(pm.list())) } pm.editing(false) } else { ko.validation.group(pm.item().err(), { deep: true }).showallmessages(true); } }
knockout.js knockout-validation
Comments
Post a Comment