I've got this jQuery code in my theme (included in the .info file) which fires and works when the user goes to node/add:
Drupal.behaviors.budgetCreate = function(context) {
//alert("WTF!");
$("#edit-submit[value='Save'][value!='Search']").parents('.button-wrapper:not(.budgetCreate-processed)').addClass('budgetCreate-processed').appendTo($('#tabset-tab-4-1'));
}What it does is remove the save button from below the set of cck fieldgroup tabs and puts it on the last tab. When the form page is loaded, it works just fine.
Several fields are required on this particular form. If I leave all fields blank and submit the form, validation kicks in and prevents the submission. The form is reloaded, but this time, the save button is not moved to the last tab.
From what I can tell, the structure is identical in both cases when the page is loaded. The button itself has the necessary ID, and it is wrapped in three span tags, the top-most of which has the 'button-wrapper' class. So why does this code work the first time but not the second time? When the page reloads, after failing validation, it does not have the class that I add the first time -- "budgetCreate-processed".
BTW, if I uncomment the alert, it fires in both cases, so I do know that the function fires, but only works once.
I have tried numerous variations on the code above. Since there are always 3 spans, I have tried using parent().parent().parent(). It works the first time, but not the second. I have used alert to display the class on the results of the parents call. In the first case, 'button-wrapper' shows up. Upon failing form validation, the class comes back as undefined. That either means the span is found but malformed, or the structure changed and firebug isn't showing it.
I expect that what I append to in this case shouldn't matter, right? I mean, the whole page is reloaded when validation fails, so should it be like a new page?
Is there a module weight issue? Perhaps the page is ready but the js in my module fires before some other js somewhere? I tried moving the code to the tabs module's js file, and I get the same issue. My theme's js file seems to at least be the last one listed on the page source.
Ideas?
Comments
hi what is budgetCreate
I have a similar problem on the site what I am building, I want to place the submit button on to the last tab. I went through your port, did not understand what is budgetCreate. I want to implement this on a node-form-education. please let me know how to use this code.
Regards
CNS