[development] Weird Javascript behavior after form_set_error on Drupal forms

David Thibault dthibault at esperion.com
Thu Dec 17 16:15:21 UTC 2009

Hello all,

I'm developing a Drupal-based Purchase Order Management module for my company.  The purchase order node form uses a few autocomplete elements as well as other JQuery bits to do a pop-up using blockUI to fill out the PO line items.  The PO line item form is hidden by default (display: none).  If I skip a required field on the parent Drupal node form (using Drupal's built-in #required => TRUE) then Drupal comes back as expected with the red form_set_error box at the top of the page listing all the required elements I skipped. However, that seems to break much of my Javascript.  Here are some specifics:

1)      Before the form is submitted the autocomplete fields go look up contacts from my Drupal contacts database (another custom module I've developed), then bring back the selected contact's mailing address and pop it into a div below the autocomplete box.  After the form_set_error returns, the autocomplete still looks up the values in the contacts database, but the resulting mailing address is not popped into the  div.

2)      Before the form is submitted there's a link entitled "Add/Edit/Delete line items" and when clicked it does a blockUI and shows the line items form in the javascript pop-up window above a grayed out screen.  After the form_set_error returns, the "Add/Edit/Delete line items" link doesn't block the UI and show the line items form.  However, the line items form is displayed on the main parent page (no longer display: none until blockUI as it was before I submitted).

I added a javascript alert at the top of $(document).ready() to show when the document is done loading, and it doesn't reappear after the form_set_error comes back, so I'm guessing it's not reloading the page when it does that.  However, I'm not sure why it would break all the javascript, or where I could intercept the form submit processing to fix the situation.  Any help for ideas of where to troubleshoot this would be appreciate.  I'd be happy to post code as well, but it's quite a bit of code so I'll spare you all the details until I get some ideas of where to drill down.  Any help would be appreciated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20091217/e90064c6/attachment.html 

More information about the development mailing list