Open bakesteve opened 13 years ago
Yes, this is on our list of features we are considering...
See also https://github.com/jquery/jquery-tmpl/issues#issue/12
https://github.com/jquery/jquery-tmpl/issues/60
Had a look at doing this and for our internal testing code, have added in the following code.
I modified the data item bind template code, and keep an array of errors within the generated template function. For now, I'm using a custom event trigger to pass the error data out - although given there is no meaningful element to trigger this off it seems strange so maybe better to raise an event from the template item, or a global tmpl event - (jQuery.tmpl.templateError?) - something similer to the tmplPlus rendered event perhaps?
This fits our needs, and think should work for others scenarios. For other errors (missing nested templates, etc) should be simple to just add to the _error collection, and maybe extend the object (at the moment just Id and Message) to have a type or some identifier? perhaps the tmpl tag? Let me know your thoughts
the changes are: line 241: open: "if($notnull_1){__.push($.encode($1a));}" + "else{_errors.push({Id:'$1',Message:'Property not found'});}"
line 320: "var _error=[];" +
line 359: "');} if(_errors.length>0){$(document).trigger('tmpl.error',_errors);} return __;"
Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.
Lookups fail silently - optionally throw / return. Would be nice to be able to optionally set a template to throw back any lookup failures (foo.bar == undefined) Or, possible have some form of error stack we can then access once the template has run? Would make unit testing much much easier, as then all I need to do is mock an object and assert / check error object. Know this was originally discussed: http://forum.jquery.com/topic/jquery-templates-proposal#14737000000767661 but cant see that it went anywhere.