Hi, I have added a modal in my application. but there is some issue I am facing. I write code on js file of modal. It works only one time. When i again open the modal the code written on js file does not work. It is loading js file only one time. Then next time it is not loading. How to make it work. Thanks
7 Answer(s)
-
0
Hi,
Can you share your modal's javascript code ? Do you use MVC, angular1 or angular2 version ?
-
0
Hi,
I am using MVC with jquery. my modal.js code is as follows.
(function($) { app.modals.ReportModel = function () {
var _modalManager; this.init = function(modalManager) { _modalManager = modalManager; //Initialize your modal here... }; this.save = function () { //Save your modal here... }; }; $('#ReportSelection').change(function () { $('.modal-title span').text($('#ReportSelection :selected').text()+ " #"); closeall($('#ReportSelection :selected').val()); $('#Report' + $('#ReportSelection :selected').val()).slideDown("fast"); }); function closeall(dontclose) { var i = 1; for (i = 1; i < 12; i++) { if(i!=dontclose) $('#Report' + i).slideUp('fast'); } }
})(jQuery);
Thanks
-
0
Hi,
can you try to use below code in your modal's init method ?
_modalManager.getModal().on('show.bs.modal', function (e) { //write your code here which will run on every shown of this modal. })
-
0
Hi, yes, i tried this. It didn't work. i had write the code as below.
code:-
(function($) { app.modals.ReportModel = function () {
var _modalManager; this.init = function(modalManager) { _modalManager = modalManager; _modalManager.getModal().on('show.bs.modal', function (e) { //write your code here which will run on every shown of this modal. $('#ReportSelection').change(function () { $('.modal-title span').text($('#ReportSelection :selected').text() + " #"); closeall($('#ReportSelection :selected').val()); $('#Report' + $('#ReportSelection :selected').val()).slideDown("fast"); }); function closeall(dontclose) { var i = 1; for (i = 1; i < 12; i++) { if (i != dontclose) $('#Report' + i).slideUp('fast'); } } }); }; this.save = function () { //Save your modal here... }; };
})(jQuery);
thanks
-
0
Hi,
I have just tested the code and it seems like you don't even need to register shown event of modal. the code inside the init function always runs when you open the modal.
Can you try to add a "console.log("modal opened....");" as the fisrt line of your modal's init function and see if it works in every modal open or not.
There might be some other problem than this in your case. If it writes log to browser console and you cannot figure it out, pleaase send your project to us via email and explain in details what you are trying to achieve.
Thanks.
-
0
Hi ,
yes , Console.log('modal opened..') . its working.. I have added all code here. Its working fine now. There is some Mismatch in modal data. I had created modal from starting now working fine. :) Thanks
-
0
Great :). Sometimes we just cannot see it.