Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I had two views on the page with two ajax exposed filter forms. Due to a bug in views, i spent a lot of time debugging JS. I found a couple of things about auto-submit :
- the change event was bubbling and triggering a click at each step. The submit button was triggered a lot of times
- textfield handling wasn't working at all
- would it be working timeoutID would probably get in the way
- there was a typo in addClass() that defeated the purpose of adding the class
Proposed resolution
- I cleaned up the selectors (based on #875020) it's actually readable now
- thanks to that, change is not bubbling anymore and textfield handling is back
- each textfield has his own timeoutID
Remaining tasks
I understand why but i'm not too happy with the way textfields are handled. You really can't be slow while typing. I'd feel better if we used change event on this too or having a config option somewhere to choose.
Comment | File | Size | Author |
---|---|---|---|
#36 | ctools-rm-bubbling-change-event-1324238-36.patch | 559 bytes | Ronino |
#35 | ctools-fix_autosubmit_bug-1324238-35.patch | 1002 bytes | jenlampton |
#25 | auto-submit-rewrite-1324238-25.patch | 3.89 KB | rlmumford |
#22 | 1324238.patch | 1 KB | soulston |
#19 | auto-submit-rewrite-1324238-19-D6.patch | 3.85 KB | mdupont |
Comments
Comment #1
nod_More on the textfield handling. I think polling for changes of the textfield value is a better way than using keyup. And this way we can trigger a change event and have only one function take care of submit. Should take care of mouse copy/paste too.
Should i open another issue or just a patch on top of this one ?
Comment #2
nod_Comment #3
nod_Sorry about that it was a half-hearted attempt, i'm rewriting my patch. It'll be there in a couple of hours.
Comment #4
nod_The first patch is the bare minimum to fix the issues. No behavior change exept the timeout for keyup that was bumped to 500ms, not much difference but avoid most premature submit when you type slowly, at least for me. The big size is only because of the indenting for the switch.
The second patch is a complete rewrite, cleaning up selectors, fixing behaviors on textfields by adding a clearTimeout on keydown and wait for bubbling change event for ctools-auto-submit-full-form.
for both radios and checkboxes are now supported.
Comment #5
merlinofchaos CreditAttribution: merlinofchaos commentedJust FYI, while I'm not at all against a patch to clean up the code, every time I see this title I am demotivated to actually look at it, because it's insulting and inaccurate.
Comment #6
nod_I'm sorry merlinofchaos. I wrote that after losing a lot of time over the issue, it's nothing personal and certainly not a judgment of the rest of the module which I appreciate. It was just an unlucky patch that got through a couple of months ago.
If you need any follow up/testing on this, I'll do my best to make up for my initial rudeness.
Comment #7
merlinofchaos CreditAttribution: merlinofchaos commentedI'm generally in favor of the cleanup you've got. My one comment:
I'd rather have these combined so that it looks more like:
Just because the way it's commented isn't as intuitive what's going on I think.
Comment #8
nod_agreed it makes more sense. The new patch uses
.once()
instead of.not()
and.addClass()
too.Thanks for taking the time to review.
Comment #9
yannickooI attached a patch here #1400802: Fix for auto-submit.js. Can we merge it with this one here? I added support for all input types and select lists.
Comment #10
nod_Ok checked both patches and mine already takes care of select and other input types. There is a
.filter('form, select, input:not(:text, :submit)')
and$('.ctools-auto-submit-full-form input:text, input:text.ctools-auto-submit')
.Can you please confirm yannickoo ?
Comment #11
nod_FYI the patch at #1400802: Fix for auto-submit.js has a bug, it binds the change event on text input which would cause issues with the special handling of text input in the second half of the file, I ran into this working on my patch too. No harm but I'm pointing it out for yannickoo, do some more testing for your next patch ;)
Comment #12
yannickooThen we could just exclude textfields with
$('... :not(input[type=text])')
?Comment #13
nod_yeah look up the patch, it's in there.
Comment #14
yannickooAh cool, why we are wating? Let's commit!
Comment #15
nod_Because merlinofchaos has his own schedule about how he does stuff. The way to help get this committed is to test it well and set RTBC if you don't find any issue. It'll inform him that he can use his time to review/commit the patch.
I can't mark it RTBC because i'm the one who wrote the patch, so it's all in your hands yannickoo :)
Comment #16
merlinofchaos CreditAttribution: merlinofchaos commentedI've just been waiting on the two of you to come to consensus. If you can test it and verify it all works as expected then I will commit it and probably right away.
Comment #17
yannickooWe should also support file inputs! And also the HTML5 inputs. We could just get them with $('input') - why you didn't do that nod_?
Comment #18
nod_I did, test the patch before asking that kind of question.
I'll make this simple by marking it RTBC #8 works and we're already on comment #18, let's close this already.
Comment #19
mdupontHere is a D6 version of the patch in #8. The only difference is that .once() doesn't exist in D6 so I used the old way of -processed classes.
Comment #20
levialliance CreditAttribution: levialliance commentedIf I'm not mistaken, the attach() function should take a context argument as per http://drupal.org/node/756722#behaviors
Edit: Fixed the .add() in response to soulston's comment below
(diff is against the patched file)
I don't know whether this should be here or in a new issue (given that this patch hasn't actually been committed yet), but the following allows ctools auto submit to work with date_popup: (again, diff is against the patched file)
Comment #21
soulston CreditAttribution: soulston commentedShouldn't this:
.add('.ctools-auto-submit')
be
.add('ctools-auto-submit')
i.e. no dot when adding the class in lines 35 and 42:
Comment #22
soulston CreditAttribution: soulston commentedHere's a patch against 7.x-1.x
Comment #23
levialliance CreditAttribution: levialliance commentedThis comment is a bit confusing: you refer to add() (which should have a dot) but your patch below only modifies addClass() calls (which shouldn't have a dot) [and were already changed in all of nod_'s patches].
Although now that you've pointed it out, the .add() in nod_'s last patch should respect the context argument.
Comment #24
soulston CreditAttribution: soulston commentedAh - yeah I see now, sorry but I patched against dev and didn't add in the patches in this issue :(
Comment #25
rlmumfordHere's a complete version of nod_'s patch with the context arguments in place. Didn't solve my problem with the media browser though, but I think thats a special case:
Comment #26
rlmumfordMY bad, this does fix the media browser problem (I was using an out of date version of views)
Comment #27
gmclelland CreditAttribution: gmclelland commentedI haven't tested the newer patches, but @nod_ patch in #8 seems to fix the issue with the Media module's "Views Media Library" view randomly redirecting the inside of the modal to the homepage when a search is performed.
Here is the issue #1319528: Media browser view library exposed form submit problem
Comment #28
merlinofchaos CreditAttribution: merlinofchaos commentedCommitted and pushed.
Comment #29
dawehnerI'm wondering whether this patch might be a possible candidate to backport to 6.x.
Comment #30
EugenMayer CreditAttribution: EugenMayer commentedi would so much love to help / see this happening for D6. Currently, the auto-submit implementation is basically unusable with textfields. I really love the functionality. What are the tasks for the backport?
Comment #31
klonosThe issue summary doesn't mention any API changes, so I'm not sure if this would be possible or not, but since you are mentioning backports, you might be interested in this #1505456: Add a "Backports" or "Drupal update" module to Drupal 7 core so that UI changes from Drupal 8 can be backported
Comment #32
merlinofchaos CreditAttribution: merlinofchaos commentedBy all means yes, please backport it.
However, 'needs review' isn't appropriate until it's actually backported. :)
Comment #33
EugenMayer CreditAttribution: EugenMayer commentedSorry, wasnt aware of which status is going to fit best - but obviously you are right :). Perfectly fine with path to be ported
Setting this on my todo-list
Comment #34
temkin CreditAttribution: temkin commentedHi guys,
First of all, thank you for the work you've already done to fix that issue. Much appreciated.
I just wanted to let you know that I still see it happening for Drupal 7. An easy way how you can reproduce it is just start typing something while previous AJAX request is still in progress.
I've spent some time looking at this issue and it looks like when AJAX request goes out the field that initiated it doesn't have "ctools-ajaxing" class on it. There is a logic that relies on that class that prevents another AJAX requests to go out until there is one in progress.
So in order to fix the issue I've done a small change:
Basically I'm just adding the missing class.
It did the trick for me and hopefully will help others to get rid of that issue.
- Artem
Comment #35
jenlamptonWell, this is a bug-fix that makes the auto-submit work by cleaning up the class name with the extra dot in it. It doesn't contain all the other fixes from @nod_'s 7.x version, but it's a start.
Comment #36
Ronino CreditAttribution: Ronino commentedThe original poster stated that the change event was bubbling and triggering multiple submits. This also happens for me on D7: change the text in a textfield, wait, the form is submitted, click outside the textfield, the form is submitted again.
I saw in the D6 patches on this page that there is no change event handler for textfields, removed it from my D7 version and all my issues are solved! Here is a D7 patch.
Comment #39
annya CreditAttribution: annya commentedCode in #34 works great for Drupal 7! But I'm not sure that we should add it in auto-submit function, because autosubmit isn't always work with ajax. Often it's just a common submit without ajax. So maybe functionality that ajaxify forms(for example views) should add this class when form is submitted.