Jquery / Handlebars error message - Uncaught TypeError: Object [object Object] has no method 'match'
This happens if you try to compile a template from a jquery element object instead of from a string. For example
<script id="my-template-script" type="text/template">...</script>
and then
var my_template = Handlebars.compile( $("#my-template-script") ); // WRONG
You might expect this to blow up right away, but it doesn't. Instead it should be
var my_template = Handlebars.compile( $("#my-template-script").html() );
If you are getting the template as text/html, then your template might be a htmlDocument. If you initialize the template as follows, then it will work fine.
function getTemplate(templateName,context, callback, errorCallback) {var template = {};template.name = templateName;$.ajax({ url: templateName, timeout: 1000, datatype: "text/javascript", error: function(jqXHR, textStatus, errorThrown) { errorCallback && errorCallback.call(context, textStatus); }, success:function(response, textStatus, jqXHR) { try { template['handlebar'] = Handlebars.compile(jqXHR.responseText); } catch(e) { console.error("error while creating Handlebars script out of template for [", template, e); throw e; } template['rawTemplate'] = jqXHR.responseText; callback && callback.call(context, template); return response; }});
}
If you use the response param instead of jqHXR.responseText then you will get the "match" not found. I have tried it.
match
apply to string only. You have to apply it to the value of the input.If it's a jQuery object, you can use _input.val()
otherwise _input.value
should work.
On the other hand, As it's part of the library, you may want to check what data type are expected as input and what you are actually sending.
null
for instance is an object in javascript, so you probably want to change it in an empty string if the library doesn't handle it.