Datepicker or other Jquery goodness inside modal window
I am able to generate the modal windows, as well as normal datepicker or autocomplete widgets from jquery, but what happens when I need to load a form inside a modal and datepicker or autocomplete be available inside the form?
It seems that the binding to the fields is tied to the window in the background. Can anyone please suggest a method to achieve this?
Thanks!
Basically I have the following code, the idea is that when I use datepicker with开发者_运维问答out any modal windows it works fine. But the moment something goes into the modal, then nothing works (as I think is a new window altogether)
<div id="modal-container"></div>
<div id="modal">
<a href="#" class="close">close</a>
</div>
which then are called upon with Ajax
$(function(){
$("#article_edited_on").datepicker();
var $modal = $('#modal'),
$modal_close = $modal.find('.close'),
$modal_container = $('#modal-container');
$('a[data-remote]').live('ajax:beforeSend', function(e, xhr, settings){
xhr.setRequestHeader('accept', '*/*;q=0.5, text/html, ' + settings.accepts.html);
});
$('a[data-remote]').live('ajax:success', function(xhr, data, status){
$modal
.html(data)
.prepend($modal_close)
.css('top', $(window).scrollTop() + 40)
.show();
$modal_container.show();
});
$('.close', '#modal').live('click', function(){
$modal_container.hide();
$modal.hide();
return false;
});
});
If, when you say 'load a form inside a modal', you mean that you are dynamically loading the form using AJAX, then you will need to initialize the fields used for datepickers/autocomplete immediately after the load is completed.
精彩评论