Bootstrap modal 'loaded' event on remote fragment
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm currently using Twitter Bootstrap modal component and i have an issue where I use jquery validation plugin on input fields in the content I load remotely using the data-remote attribute.
Because the content is loaded after jquery validation has run across the dom, validation doesn't occur for the newly loaded elements.
I have a solution where I modify bootstrap.js (the modal class), see below.
var Modal = function (element, options) {
this.options = options
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
//this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
this.options.remote && this.$element.find('.modal-body').load(this.options.remote, $.proxy(function () {
this.$element.trigger('loaded')
}, this)) //my additions
}
I trigger a 'loaded' event to the call that loads the external html fragment.
I already have this event wired up and i call the validation on the newly loaded elements.
$('#myModal').on('loaded', function () {
$.validator.unobtrusive.parse($(this));
});
My issue is that I had to modify bootstrap.js to achieve this, is there a way I can have this working externally without modifying bootstrap.js? Is there a way to access the modal object on a page and attach the 'loaded' event to it? i'd like to do this in an external script or within a page so i don't need to worry about bootstrap versions.
javascript asp.net-mvc-4 twitter-bootstrap jquery-validate unobtrusive-validation
add a comment |
I'm currently using Twitter Bootstrap modal component and i have an issue where I use jquery validation plugin on input fields in the content I load remotely using the data-remote attribute.
Because the content is loaded after jquery validation has run across the dom, validation doesn't occur for the newly loaded elements.
I have a solution where I modify bootstrap.js (the modal class), see below.
var Modal = function (element, options) {
this.options = options
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
//this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
this.options.remote && this.$element.find('.modal-body').load(this.options.remote, $.proxy(function () {
this.$element.trigger('loaded')
}, this)) //my additions
}
I trigger a 'loaded' event to the call that loads the external html fragment.
I already have this event wired up and i call the validation on the newly loaded elements.
$('#myModal').on('loaded', function () {
$.validator.unobtrusive.parse($(this));
});
My issue is that I had to modify bootstrap.js to achieve this, is there a way I can have this working externally without modifying bootstrap.js? Is there a way to access the modal object on a page and attach the 'loaded' event to it? i'd like to do this in an external script or within a page so i don't need to worry about bootstrap versions.
javascript asp.net-mvc-4 twitter-bootstrap jquery-validate unobtrusive-validation
Is there an issue with doing the validation in theshownevent of the modal?
– mccannf
Sep 23 '13 at 14:01
@mccannf For remote content, the shown triggers before the new elements are loaded.
– scartag
Sep 23 '13 at 14:03
add a comment |
I'm currently using Twitter Bootstrap modal component and i have an issue where I use jquery validation plugin on input fields in the content I load remotely using the data-remote attribute.
Because the content is loaded after jquery validation has run across the dom, validation doesn't occur for the newly loaded elements.
I have a solution where I modify bootstrap.js (the modal class), see below.
var Modal = function (element, options) {
this.options = options
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
//this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
this.options.remote && this.$element.find('.modal-body').load(this.options.remote, $.proxy(function () {
this.$element.trigger('loaded')
}, this)) //my additions
}
I trigger a 'loaded' event to the call that loads the external html fragment.
I already have this event wired up and i call the validation on the newly loaded elements.
$('#myModal').on('loaded', function () {
$.validator.unobtrusive.parse($(this));
});
My issue is that I had to modify bootstrap.js to achieve this, is there a way I can have this working externally without modifying bootstrap.js? Is there a way to access the modal object on a page and attach the 'loaded' event to it? i'd like to do this in an external script or within a page so i don't need to worry about bootstrap versions.
javascript asp.net-mvc-4 twitter-bootstrap jquery-validate unobtrusive-validation
I'm currently using Twitter Bootstrap modal component and i have an issue where I use jquery validation plugin on input fields in the content I load remotely using the data-remote attribute.
Because the content is loaded after jquery validation has run across the dom, validation doesn't occur for the newly loaded elements.
I have a solution where I modify bootstrap.js (the modal class), see below.
var Modal = function (element, options) {
this.options = options
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
//this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
this.options.remote && this.$element.find('.modal-body').load(this.options.remote, $.proxy(function () {
this.$element.trigger('loaded')
}, this)) //my additions
}
I trigger a 'loaded' event to the call that loads the external html fragment.
I already have this event wired up and i call the validation on the newly loaded elements.
$('#myModal').on('loaded', function () {
$.validator.unobtrusive.parse($(this));
});
My issue is that I had to modify bootstrap.js to achieve this, is there a way I can have this working externally without modifying bootstrap.js? Is there a way to access the modal object on a page and attach the 'loaded' event to it? i'd like to do this in an external script or within a page so i don't need to worry about bootstrap versions.
javascript asp.net-mvc-4 twitter-bootstrap jquery-validate unobtrusive-validation
javascript asp.net-mvc-4 twitter-bootstrap jquery-validate unobtrusive-validation
edited Sep 23 '13 at 12:36
scartag
asked Sep 23 '13 at 12:29
scartagscartag
16k33950
16k33950
Is there an issue with doing the validation in theshownevent of the modal?
– mccannf
Sep 23 '13 at 14:01
@mccannf For remote content, the shown triggers before the new elements are loaded.
– scartag
Sep 23 '13 at 14:03
add a comment |
Is there an issue with doing the validation in theshownevent of the modal?
– mccannf
Sep 23 '13 at 14:01
@mccannf For remote content, the shown triggers before the new elements are loaded.
– scartag
Sep 23 '13 at 14:03
Is there an issue with doing the validation in the
shown event of the modal?– mccannf
Sep 23 '13 at 14:01
Is there an issue with doing the validation in the
shown event of the modal?– mccannf
Sep 23 '13 at 14:01
@mccannf For remote content, the shown triggers before the new elements are loaded.
– scartag
Sep 23 '13 at 14:03
@mccannf For remote content, the shown triggers before the new elements are loaded.
– scartag
Sep 23 '13 at 14:03
add a comment |
4 Answers
4
active
oldest
votes
According to both these issues:
https://github.com/twbs/bootstrap/issues/5169
https://github.com/twbs/bootstrap/pull/6846
..as of now the Bootstrap developers are digging their heels in and refusing to add a loaded event into Bootstrap.
So instead they recommend you avoid using the data-remote markup and load the data yourself into the modal:
$('#myModal').modal(your_options).find('.modal-body').load('request_url', function () {
// do cool stuff here all day… no need to change bootstrap
}')
You are great! Thank for this solution! This helped me with this problem: stackoverflow.com/questions/20339958/…
– Anton
Jan 16 '14 at 15:42
7
Just a quick note so people don't just go with the accepted answer without checking. Bootstrap has had a 'loaded.bs.modal' event for a while now - getbootstrap.com/javascript/#modals.
– Jay
Feb 27 '15 at 4:42
add a comment |
Just an update here:
Bootstrap has added a loaded event.
http://getbootstrap.com/javascript/#modals
capture the 'loaded.bs.modal' event on the modal
$('#myModal').on('loaded.bs.modal', function (e) {
// do cool stuff here all day… no need to change bootstrap
})
5
Thanks you prevented me from having no more hair on my head!
– Augustin Riedinger
Oct 17 '14 at 21:09
1
Please remove the ' from the last line. It should be }) not }')
– Sugato
Dec 24 '14 at 9:31
1
This event work only when content of the modal is loaded with remote option, if the content is embeded in the html modal not work
– xzegga
Jan 6 '16 at 16:10
Any idea when this was added? It's not working for me
– Glen
Mar 16 '17 at 16:04
1
This work when we need to call a function after loading script in bootstrap remote modal . Thank you.
– Ehsan Chavoshi
May 16 '17 at 17:00
add a comment |
The 'loaded.bs.modal' event doesn't work for me, so I have tried the 'shown.bs.modal' event and it's works fine :
$('#myModal').on('shown.bs.modal', function () {
// do cool stuff here...
});
This event is captured after the modal is shown.
I hope this will help someone :)
2
the modals first shows, then loads the remote content, so it doesn't work
– Ignacio Vazquez
May 6 '15 at 16:55
This isn't relevant to the question. The question involves ajax loaded content and 'shown' is never triggered as a product of an ajax response.
– Du3
Mar 1 '16 at 0:03
1
Worked for me too. My modal-body is loaded with ajax, then shown. Maybe not relevant to the question, but helpful for some of us :-)
– Nik
Apr 21 '16 at 13:22
add a comment |
I had a rather interesting catch, In my case, on localhost, the event loaded.bs.modal was firing before the event shown.bs.modal since on local host the act of fetching the data from the "remote" url(which was local btw), was happening instanteneously even before the bootstrap could finish its transition and trigger the shown.bs.modal event.
But on a webserver the events were firing in the perceived order.
First the shown.bs.modal was being triggered and then owing to the pragmatic latency of the remote url, the event loaded.bs.modal was being triggered.
What I wanted is to grab an event whichever happened the last.
So to solve it I came up with my own implementation as below. YMMV, Now there are a lot of assumptions here, so take the below code as just a POC and with a grain of salt rather than a full fledged code.
jQuery('#myModal').on('shown.bs.modal', function () {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "loaded.bs.modal" hasn't yet been triggered
}
});
jQuery('#myModal').on('loaded.bs.modal', function (e) {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "shown.bs.modal" hasn't yet been triggered
} else {
// Do something ONLY IF "shown.bs.modal" hasn already been triggered
}
});
jQuery('#myModal').on('hidden.bs.modal', function () {
jQuery('#myModal .modal-content').html('<div class="resetFlag" style="display:none;"></div>');
showModalLoader();
});
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18959258%2fbootstrap-modal-loaded-event-on-remote-fragment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
According to both these issues:
https://github.com/twbs/bootstrap/issues/5169
https://github.com/twbs/bootstrap/pull/6846
..as of now the Bootstrap developers are digging their heels in and refusing to add a loaded event into Bootstrap.
So instead they recommend you avoid using the data-remote markup and load the data yourself into the modal:
$('#myModal').modal(your_options).find('.modal-body').load('request_url', function () {
// do cool stuff here all day… no need to change bootstrap
}')
You are great! Thank for this solution! This helped me with this problem: stackoverflow.com/questions/20339958/…
– Anton
Jan 16 '14 at 15:42
7
Just a quick note so people don't just go with the accepted answer without checking. Bootstrap has had a 'loaded.bs.modal' event for a while now - getbootstrap.com/javascript/#modals.
– Jay
Feb 27 '15 at 4:42
add a comment |
According to both these issues:
https://github.com/twbs/bootstrap/issues/5169
https://github.com/twbs/bootstrap/pull/6846
..as of now the Bootstrap developers are digging their heels in and refusing to add a loaded event into Bootstrap.
So instead they recommend you avoid using the data-remote markup and load the data yourself into the modal:
$('#myModal').modal(your_options).find('.modal-body').load('request_url', function () {
// do cool stuff here all day… no need to change bootstrap
}')
You are great! Thank for this solution! This helped me with this problem: stackoverflow.com/questions/20339958/…
– Anton
Jan 16 '14 at 15:42
7
Just a quick note so people don't just go with the accepted answer without checking. Bootstrap has had a 'loaded.bs.modal' event for a while now - getbootstrap.com/javascript/#modals.
– Jay
Feb 27 '15 at 4:42
add a comment |
According to both these issues:
https://github.com/twbs/bootstrap/issues/5169
https://github.com/twbs/bootstrap/pull/6846
..as of now the Bootstrap developers are digging their heels in and refusing to add a loaded event into Bootstrap.
So instead they recommend you avoid using the data-remote markup and load the data yourself into the modal:
$('#myModal').modal(your_options).find('.modal-body').load('request_url', function () {
// do cool stuff here all day… no need to change bootstrap
}')
According to both these issues:
https://github.com/twbs/bootstrap/issues/5169
https://github.com/twbs/bootstrap/pull/6846
..as of now the Bootstrap developers are digging their heels in and refusing to add a loaded event into Bootstrap.
So instead they recommend you avoid using the data-remote markup and load the data yourself into the modal:
$('#myModal').modal(your_options).find('.modal-body').load('request_url', function () {
// do cool stuff here all day… no need to change bootstrap
}')
answered Sep 23 '13 at 14:07
mccannfmccannf
15.6k34362
15.6k34362
You are great! Thank for this solution! This helped me with this problem: stackoverflow.com/questions/20339958/…
– Anton
Jan 16 '14 at 15:42
7
Just a quick note so people don't just go with the accepted answer without checking. Bootstrap has had a 'loaded.bs.modal' event for a while now - getbootstrap.com/javascript/#modals.
– Jay
Feb 27 '15 at 4:42
add a comment |
You are great! Thank for this solution! This helped me with this problem: stackoverflow.com/questions/20339958/…
– Anton
Jan 16 '14 at 15:42
7
Just a quick note so people don't just go with the accepted answer without checking. Bootstrap has had a 'loaded.bs.modal' event for a while now - getbootstrap.com/javascript/#modals.
– Jay
Feb 27 '15 at 4:42
You are great! Thank for this solution! This helped me with this problem: stackoverflow.com/questions/20339958/…
– Anton
Jan 16 '14 at 15:42
You are great! Thank for this solution! This helped me with this problem: stackoverflow.com/questions/20339958/…
– Anton
Jan 16 '14 at 15:42
7
7
Just a quick note so people don't just go with the accepted answer without checking. Bootstrap has had a 'loaded.bs.modal' event for a while now - getbootstrap.com/javascript/#modals.
– Jay
Feb 27 '15 at 4:42
Just a quick note so people don't just go with the accepted answer without checking. Bootstrap has had a 'loaded.bs.modal' event for a while now - getbootstrap.com/javascript/#modals.
– Jay
Feb 27 '15 at 4:42
add a comment |
Just an update here:
Bootstrap has added a loaded event.
http://getbootstrap.com/javascript/#modals
capture the 'loaded.bs.modal' event on the modal
$('#myModal').on('loaded.bs.modal', function (e) {
// do cool stuff here all day… no need to change bootstrap
})
5
Thanks you prevented me from having no more hair on my head!
– Augustin Riedinger
Oct 17 '14 at 21:09
1
Please remove the ' from the last line. It should be }) not }')
– Sugato
Dec 24 '14 at 9:31
1
This event work only when content of the modal is loaded with remote option, if the content is embeded in the html modal not work
– xzegga
Jan 6 '16 at 16:10
Any idea when this was added? It's not working for me
– Glen
Mar 16 '17 at 16:04
1
This work when we need to call a function after loading script in bootstrap remote modal . Thank you.
– Ehsan Chavoshi
May 16 '17 at 17:00
add a comment |
Just an update here:
Bootstrap has added a loaded event.
http://getbootstrap.com/javascript/#modals
capture the 'loaded.bs.modal' event on the modal
$('#myModal').on('loaded.bs.modal', function (e) {
// do cool stuff here all day… no need to change bootstrap
})
5
Thanks you prevented me from having no more hair on my head!
– Augustin Riedinger
Oct 17 '14 at 21:09
1
Please remove the ' from the last line. It should be }) not }')
– Sugato
Dec 24 '14 at 9:31
1
This event work only when content of the modal is loaded with remote option, if the content is embeded in the html modal not work
– xzegga
Jan 6 '16 at 16:10
Any idea when this was added? It's not working for me
– Glen
Mar 16 '17 at 16:04
1
This work when we need to call a function after loading script in bootstrap remote modal . Thank you.
– Ehsan Chavoshi
May 16 '17 at 17:00
add a comment |
Just an update here:
Bootstrap has added a loaded event.
http://getbootstrap.com/javascript/#modals
capture the 'loaded.bs.modal' event on the modal
$('#myModal').on('loaded.bs.modal', function (e) {
// do cool stuff here all day… no need to change bootstrap
})
Just an update here:
Bootstrap has added a loaded event.
http://getbootstrap.com/javascript/#modals
capture the 'loaded.bs.modal' event on the modal
$('#myModal').on('loaded.bs.modal', function (e) {
// do cool stuff here all day… no need to change bootstrap
})
edited Jan 2 '15 at 20:07
answered Apr 7 '14 at 21:00
GeorgeGeorge
3,07232131
3,07232131
5
Thanks you prevented me from having no more hair on my head!
– Augustin Riedinger
Oct 17 '14 at 21:09
1
Please remove the ' from the last line. It should be }) not }')
– Sugato
Dec 24 '14 at 9:31
1
This event work only when content of the modal is loaded with remote option, if the content is embeded in the html modal not work
– xzegga
Jan 6 '16 at 16:10
Any idea when this was added? It's not working for me
– Glen
Mar 16 '17 at 16:04
1
This work when we need to call a function after loading script in bootstrap remote modal . Thank you.
– Ehsan Chavoshi
May 16 '17 at 17:00
add a comment |
5
Thanks you prevented me from having no more hair on my head!
– Augustin Riedinger
Oct 17 '14 at 21:09
1
Please remove the ' from the last line. It should be }) not }')
– Sugato
Dec 24 '14 at 9:31
1
This event work only when content of the modal is loaded with remote option, if the content is embeded in the html modal not work
– xzegga
Jan 6 '16 at 16:10
Any idea when this was added? It's not working for me
– Glen
Mar 16 '17 at 16:04
1
This work when we need to call a function after loading script in bootstrap remote modal . Thank you.
– Ehsan Chavoshi
May 16 '17 at 17:00
5
5
Thanks you prevented me from having no more hair on my head!
– Augustin Riedinger
Oct 17 '14 at 21:09
Thanks you prevented me from having no more hair on my head!
– Augustin Riedinger
Oct 17 '14 at 21:09
1
1
Please remove the ' from the last line. It should be }) not }')
– Sugato
Dec 24 '14 at 9:31
Please remove the ' from the last line. It should be }) not }')
– Sugato
Dec 24 '14 at 9:31
1
1
This event work only when content of the modal is loaded with remote option, if the content is embeded in the html modal not work
– xzegga
Jan 6 '16 at 16:10
This event work only when content of the modal is loaded with remote option, if the content is embeded in the html modal not work
– xzegga
Jan 6 '16 at 16:10
Any idea when this was added? It's not working for me
– Glen
Mar 16 '17 at 16:04
Any idea when this was added? It's not working for me
– Glen
Mar 16 '17 at 16:04
1
1
This work when we need to call a function after loading script in bootstrap remote modal . Thank you.
– Ehsan Chavoshi
May 16 '17 at 17:00
This work when we need to call a function after loading script in bootstrap remote modal . Thank you.
– Ehsan Chavoshi
May 16 '17 at 17:00
add a comment |
The 'loaded.bs.modal' event doesn't work for me, so I have tried the 'shown.bs.modal' event and it's works fine :
$('#myModal').on('shown.bs.modal', function () {
// do cool stuff here...
});
This event is captured after the modal is shown.
I hope this will help someone :)
2
the modals first shows, then loads the remote content, so it doesn't work
– Ignacio Vazquez
May 6 '15 at 16:55
This isn't relevant to the question. The question involves ajax loaded content and 'shown' is never triggered as a product of an ajax response.
– Du3
Mar 1 '16 at 0:03
1
Worked for me too. My modal-body is loaded with ajax, then shown. Maybe not relevant to the question, but helpful for some of us :-)
– Nik
Apr 21 '16 at 13:22
add a comment |
The 'loaded.bs.modal' event doesn't work for me, so I have tried the 'shown.bs.modal' event and it's works fine :
$('#myModal').on('shown.bs.modal', function () {
// do cool stuff here...
});
This event is captured after the modal is shown.
I hope this will help someone :)
2
the modals first shows, then loads the remote content, so it doesn't work
– Ignacio Vazquez
May 6 '15 at 16:55
This isn't relevant to the question. The question involves ajax loaded content and 'shown' is never triggered as a product of an ajax response.
– Du3
Mar 1 '16 at 0:03
1
Worked for me too. My modal-body is loaded with ajax, then shown. Maybe not relevant to the question, but helpful for some of us :-)
– Nik
Apr 21 '16 at 13:22
add a comment |
The 'loaded.bs.modal' event doesn't work for me, so I have tried the 'shown.bs.modal' event and it's works fine :
$('#myModal').on('shown.bs.modal', function () {
// do cool stuff here...
});
This event is captured after the modal is shown.
I hope this will help someone :)
The 'loaded.bs.modal' event doesn't work for me, so I have tried the 'shown.bs.modal' event and it's works fine :
$('#myModal').on('shown.bs.modal', function () {
// do cool stuff here...
});
This event is captured after the modal is shown.
I hope this will help someone :)
edited Mar 2 '16 at 16:44
answered Feb 24 '15 at 11:23
Mohammed Réda OUASSINIMohammed Réda OUASSINI
36548
36548
2
the modals first shows, then loads the remote content, so it doesn't work
– Ignacio Vazquez
May 6 '15 at 16:55
This isn't relevant to the question. The question involves ajax loaded content and 'shown' is never triggered as a product of an ajax response.
– Du3
Mar 1 '16 at 0:03
1
Worked for me too. My modal-body is loaded with ajax, then shown. Maybe not relevant to the question, but helpful for some of us :-)
– Nik
Apr 21 '16 at 13:22
add a comment |
2
the modals first shows, then loads the remote content, so it doesn't work
– Ignacio Vazquez
May 6 '15 at 16:55
This isn't relevant to the question. The question involves ajax loaded content and 'shown' is never triggered as a product of an ajax response.
– Du3
Mar 1 '16 at 0:03
1
Worked for me too. My modal-body is loaded with ajax, then shown. Maybe not relevant to the question, but helpful for some of us :-)
– Nik
Apr 21 '16 at 13:22
2
2
the modals first shows, then loads the remote content, so it doesn't work
– Ignacio Vazquez
May 6 '15 at 16:55
the modals first shows, then loads the remote content, so it doesn't work
– Ignacio Vazquez
May 6 '15 at 16:55
This isn't relevant to the question. The question involves ajax loaded content and 'shown' is never triggered as a product of an ajax response.
– Du3
Mar 1 '16 at 0:03
This isn't relevant to the question. The question involves ajax loaded content and 'shown' is never triggered as a product of an ajax response.
– Du3
Mar 1 '16 at 0:03
1
1
Worked for me too. My modal-body is loaded with ajax, then shown. Maybe not relevant to the question, but helpful for some of us :-)
– Nik
Apr 21 '16 at 13:22
Worked for me too. My modal-body is loaded with ajax, then shown. Maybe not relevant to the question, but helpful for some of us :-)
– Nik
Apr 21 '16 at 13:22
add a comment |
I had a rather interesting catch, In my case, on localhost, the event loaded.bs.modal was firing before the event shown.bs.modal since on local host the act of fetching the data from the "remote" url(which was local btw), was happening instanteneously even before the bootstrap could finish its transition and trigger the shown.bs.modal event.
But on a webserver the events were firing in the perceived order.
First the shown.bs.modal was being triggered and then owing to the pragmatic latency of the remote url, the event loaded.bs.modal was being triggered.
What I wanted is to grab an event whichever happened the last.
So to solve it I came up with my own implementation as below. YMMV, Now there are a lot of assumptions here, so take the below code as just a POC and with a grain of salt rather than a full fledged code.
jQuery('#myModal').on('shown.bs.modal', function () {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "loaded.bs.modal" hasn't yet been triggered
}
});
jQuery('#myModal').on('loaded.bs.modal', function (e) {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "shown.bs.modal" hasn't yet been triggered
} else {
// Do something ONLY IF "shown.bs.modal" hasn already been triggered
}
});
jQuery('#myModal').on('hidden.bs.modal', function () {
jQuery('#myModal .modal-content').html('<div class="resetFlag" style="display:none;"></div>');
showModalLoader();
});
add a comment |
I had a rather interesting catch, In my case, on localhost, the event loaded.bs.modal was firing before the event shown.bs.modal since on local host the act of fetching the data from the "remote" url(which was local btw), was happening instanteneously even before the bootstrap could finish its transition and trigger the shown.bs.modal event.
But on a webserver the events were firing in the perceived order.
First the shown.bs.modal was being triggered and then owing to the pragmatic latency of the remote url, the event loaded.bs.modal was being triggered.
What I wanted is to grab an event whichever happened the last.
So to solve it I came up with my own implementation as below. YMMV, Now there are a lot of assumptions here, so take the below code as just a POC and with a grain of salt rather than a full fledged code.
jQuery('#myModal').on('shown.bs.modal', function () {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "loaded.bs.modal" hasn't yet been triggered
}
});
jQuery('#myModal').on('loaded.bs.modal', function (e) {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "shown.bs.modal" hasn't yet been triggered
} else {
// Do something ONLY IF "shown.bs.modal" hasn already been triggered
}
});
jQuery('#myModal').on('hidden.bs.modal', function () {
jQuery('#myModal .modal-content').html('<div class="resetFlag" style="display:none;"></div>');
showModalLoader();
});
add a comment |
I had a rather interesting catch, In my case, on localhost, the event loaded.bs.modal was firing before the event shown.bs.modal since on local host the act of fetching the data from the "remote" url(which was local btw), was happening instanteneously even before the bootstrap could finish its transition and trigger the shown.bs.modal event.
But on a webserver the events were firing in the perceived order.
First the shown.bs.modal was being triggered and then owing to the pragmatic latency of the remote url, the event loaded.bs.modal was being triggered.
What I wanted is to grab an event whichever happened the last.
So to solve it I came up with my own implementation as below. YMMV, Now there are a lot of assumptions here, so take the below code as just a POC and with a grain of salt rather than a full fledged code.
jQuery('#myModal').on('shown.bs.modal', function () {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "loaded.bs.modal" hasn't yet been triggered
}
});
jQuery('#myModal').on('loaded.bs.modal', function (e) {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "shown.bs.modal" hasn't yet been triggered
} else {
// Do something ONLY IF "shown.bs.modal" hasn already been triggered
}
});
jQuery('#myModal').on('hidden.bs.modal', function () {
jQuery('#myModal .modal-content').html('<div class="resetFlag" style="display:none;"></div>');
showModalLoader();
});
I had a rather interesting catch, In my case, on localhost, the event loaded.bs.modal was firing before the event shown.bs.modal since on local host the act of fetching the data from the "remote" url(which was local btw), was happening instanteneously even before the bootstrap could finish its transition and trigger the shown.bs.modal event.
But on a webserver the events were firing in the perceived order.
First the shown.bs.modal was being triggered and then owing to the pragmatic latency of the remote url, the event loaded.bs.modal was being triggered.
What I wanted is to grab an event whichever happened the last.
So to solve it I came up with my own implementation as below. YMMV, Now there are a lot of assumptions here, so take the below code as just a POC and with a grain of salt rather than a full fledged code.
jQuery('#myModal').on('shown.bs.modal', function () {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "loaded.bs.modal" hasn't yet been triggered
}
});
jQuery('#myModal').on('loaded.bs.modal', function (e) {
if (jQuery(this).find('.resetFlag').length) {
// Do something ONLY IF "shown.bs.modal" hasn't yet been triggered
} else {
// Do something ONLY IF "shown.bs.modal" hasn already been triggered
}
});
jQuery('#myModal').on('hidden.bs.modal', function () {
jQuery('#myModal .modal-content').html('<div class="resetFlag" style="display:none;"></div>');
showModalLoader();
});
answered Nov 16 '18 at 12:14
Mohd Abdul MujibMohd Abdul Mujib
6,74944063
6,74944063
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18959258%2fbootstrap-modal-loaded-event-on-remote-fragment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is there an issue with doing the validation in the
shownevent of the modal?– mccannf
Sep 23 '13 at 14:01
@mccannf For remote content, the shown triggers before the new elements are loaded.
– scartag
Sep 23 '13 at 14:03