Rene Rene - 5 months ago 46
Javascript Question

Handlebars form submit does not work

I have a form that within a handlebars put the submit does not work, I have to do? Can anyone help?



<script id="chat-window-template" type="text/x-handlebars-template">
<a href="#" class="close"><i class="fa fa-times"></i></a>
<a href="#">
<span class="pull-left">
<img src="{{ user_image }}" width="40">
</span>
<span class="contact-name">{{user}}</span>
</a>
<div class="panel-body" id="chat-bill">
<form id="messageForm">
<input id="nameInput" type="hidden" class="input-medium" value="Macbook" />
<input id="messageInput" type="text" class="form-control" placeholder="Digite uma mensagem..." />
<input type="submit" value="Send" />
</form>
</div>
</script>





$("#messageForm").submit( function() {alert();});

Answer

Perhaps handler is attached before Dom is compiled, try listening t body events, and filtering by selector, should listen to Dom nodes added in future too...

$(document.body).on("submit", "#messageForm", function() {alert();});
Comments