Closed (fixed)
Project:
Uniqueness
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
19 Jan 2013 at 22:23 UTC
Updated:
4 Feb 2013 at 17:30 UTC
Jump to comment: Most recent file
Because the javascript is added to the page directly, if the form is rebuilt from cache, as happens when there is a validation failure, the javascript is lost. To demonstrate this bug, try to add a node with a blank title. After the validation failure, note that uniqueness no longer works.
For 7.x, the fix is easy: use the new $form['#attached'] FAPI option to attach the jQuery and settings to the form.
For 6.x, the javascript will have to be added in an after_build function, rather than the alter function. The after_build is called after when the form is rebuilt from cache.
I will post up a patch for 7.x, along with a little clean-up, once I get back in sync on other outstanding issues.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | validation_loses_js-1893458-2.patch | 3.69 KB | danchadwick |
Comments
Comment #1
bforchhammer commentedUh, that's bad. For 7.x the #attached thing is definitely the right way forward. We need to make sure it works with the block as well as the inline widget.
For 6.x there's already #1316200: Uniqueness widget doesn't work if form validation errors appear which sounds related and already has a patch. Looks like it just needs testing and verification...
Comment #2
danchadwick commentedTook the opportunity to clean things up a bit. Also noticed that the preview was not being set properly because the function didn't have access to $form_state. I'm passing the preview setting into the function now.
Also because we are injecting the js into the form element, $form['uniqueness'] is now guaranteed to be set, so I removed the if (isset()) for it. I also added the uniqueness_type into the array that is added to the existing array, eliminating the need for the isset test on that too. A bit cleaner, I think, but if you disagree feel free to put it back.
Again, thanks for your help. Lot's of progress in the last day!
Comment #3
danchadwick commentedPS I tested it in inline, in the block, and both, as well as in preview. All seems fine and I see no reason why it wouldn't be.
Comment #4
bforchhammer commentedThanks.