I want to enable a button in a jsViews/JsRender template that retrieves employee comments from a database. That part works fine. But I need a button that says 'Reply' so others can add their comments to a post. When that button is clicked, a modal should appear allowing them to enter text.
The button does appear as it should but I cannot get it to perform an action (like fire an alert box, much less a modal). The demos on the jsViews/jsRender websites work in my server environment, so I know its not a browser or CDN issue.
My first attempt was just to enable the button through jQuery:
<script id="theTmpl2" type="text/x-jsrender">
<div class="row">
<div class="card">
<li class="list-group-item">
<div class="card-block">
<h6 class="card-title"><b>{{:first_name}} {{:last_name}}
{{:id}}
</b></h6>
<p class="card-text text-muted large">
<b>Employee ID:</b> {{:emp_id}}<br>
<b>Employee:</b> {{:emp_first}} {{:emp_last}} <br>
<b>Subject:</b> {{:subject}} <br>
<b>Message:</b> {{:message}} <br>
<b>Post Type:</b> {{:post_type}} <br>
<b>Time:</b> {{:timestamp}} <br>
</p>
<button type="button" class="btn btn-primary btn-sm"
id="reply_btn">Reply</button>
<button type="button" class="btn btn-success btn-sm"
id="new_post_btn">New Post</button>
</li>
</div>
</div>
</div>
</script>
<script id="theTmpl2" type="text/x-jsrender">
<div class="row">
<div class="card">
<li class="list-group-item">
<div class="card-block">
<h6 class="card-title"><b>{{:first_name}} {{:last_name}} {{:id}}
</b></h6>
<p class="card-text text-muted large">
<b>Employee ID:</b> {{:emp_id}}<br>
<b>Employee:</b> {{:emp_first}} {{:emp_last}} <br>
<b>Subject:</b> {{:subject}} <br>
<b>Message:</b> {{:message}} <br>
<b>Post Type:</b> {{:post_type}} <br>
<b>Time:</b> {{:timestamp}} <br>
</p>
<button type="button" class="btn btn-primary btn-sm"
id="reply_btn">Reply</button>
<button type="button" class="btn btn-success btn-sm"
id="new_post_btn">New Post</button>
</li>
</div>
</div>
<script>
$( "#new_post_btn" ).click(function() {
alert( "Handler for .click() called." );
});
</script>
I then tried (from the demo on the website):
<button type="button" class="btn btn-primary btn-sm"
id="reply_btn">Reply</button>
<button type="button" class="btn btn-success btn-sm"
id="new_post_btn">New Post</button>
<span id="topLinked">
<button data-link="{on ~doSomething}">top level</button>
</span>
<script id="tmpl" type="text/x-jsrender">
<button data-link="{on ~doSomething}">in template</button>
With this script:
<script>
var person = {};
var helpers = {
doSomething: function() {
alert("do something");
}
}
$.link(true, "#topLinked", person, helpers); // Data-link top-
level content
</script>
In my first attempt, with the jQuery approach, the button does appear on screen, but when I click it nothing happens.
In my second attempt, again two buttons appear ('doSomething') but when I click on them - nothing.
I also tried several other approaches described in the demos on the jsViews/jsRender site but those too were unsuccessful.