Meteor's Session.set causing duplicate the Bootstrap modal? -
i using meteor 0.6.2.1.
i have encountered strange issue bootstrap modal when call meteor's session.set().
i want show simple modal dialogue , update data when user clicks on template instance.
i copy bootstrap modal example .html file:
<body> {{> hello}} {{> alert}} </body> <template name="hello"> <h1>hello world!</h1> {{greeting}} <input type="button" value="click" /> <br/> <!-- button trigger modal --> <a href="#mymodal" role="button" class="btn" data-toggle="modal">launch demo modal</a> </template> <template name="alert"> <!-- modal --> <div id="mymodal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="mymodallabel">modal header</h3> </div> <div class="modal-body"> <p>one fine body…</p> <p>data = {{data}}</p> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal" aria-hidden="true">close</button> <button class="btn btn-primary">save changes</button> </div> </div> </template>
and set data when button click:
if (meteor.isclient) { session.set("data", "abcd"); template.hello.greeting = function() { return "welcome use-bootstrap."; }; template.alert.data = function() { return session.get("data"); }; template.hello.events({ 'click input': function() { if (typeof console !== "undefined" && console !== null) { return console.log("you pressed button"); } } }); template.hello.events({ 'click .btn': function() { var randomid; randomid = random.id(); console.log("data = " + session.get("data")); // cause duplicate template.alert session.set("data", randomid); } }); } if (meteor.isserver) { meteor.startup(function() { return console.log("server start!!"); }); }
i use chrome debug , see modal element duplicate when click button.
what's matter code?
i'm not 100% sure why happening believe has references modal node kept in js code (bootstrap).
to solve added:
template.alert.preserve(["#mymodal"]);
from meteor docs:
preservation useful in variety of cases replacing dom element identical or modified element not have same effect retaining original element. these include:
- input text fields , other form controls
- elements css animations
- iframes
- nodes references kept in javascript code
Comments
Post a Comment