dialog in tab not refreshing
OK. I have an admin interface that uses tabs. I have some modal forms in the tabs. This is all good while everything is static.
I then made the tabs content load using ajax. This is also fine and works well. Everything is going swimmingly.
Here's the problem.
The modal forms get content from the database. So, on tab 0 my form uses information that can be edited on tab 1.
When I go to tab1 and edit the info, then return to tab 0 I can see that the dialog is the original dialog. Firebug shows me that a modified form was returned to the browser.
If I destroy the dialog when I go to tab 1 then I can never get it back again.
Here's the code to initialise the tabs. I've turned off all the caching I know about.
- $(function() {
- $("#adminTabs").tabs({
- cache: false,
- ajaxOptions: {cache:false},
- load:function(){
- initTabs();
- }
- });
- });
Now I initialise the correct javascript for the relevant tab... addin click handlers etc...
- function initTabs(){
- var selected = $('#adminTabs').tabs('option', 'selected');
- switch (selected){
- case 1:
- $('#campaignScheduler').dialog('destroy');
- initDefintion();
- break;
-
default:
- initCampaign();
- }
- }
And the cut down (you don't need everything!!) code for initialising my dialog...
- function initCampaign(){
- $('input:button','#campaignButtons, #newCampaignButtons').button();
- $('#campaignScheduler').dialog({autoOpen: false, modal:true});
- $('#newCampaign').click(function(){
- // Clear all the form elements
- $('#campaignName').val(null);
- $('#campaignDescription').val(null);
- // Open the dialog
$('#campaignScheduler').dialog('open');
- });
- // Do more stuff
- }
If I alert out the result of .dialog("isOpen") in my click handler then I get some interesting results...
- Without the destroy I always get false.
- With the destroy in place, even though I then create the dialog again in the initCampaign function, I get false on the first visit to my tab. Subsequent visits then alert out [object object].
I'd rather not have to introduce more code to reload the form via yet another ajax call when my open button is clicked.
Does anyone out there have any idea why it's behaving in this way and how I can get it to rebuild the dialog with the new content that's loaded via ajax?
Many thanks