Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 UTC on 18 March 2024, to get $100 off your ticket.
Views exposed filters show the chosen selects correctly when the page first loads. However, after the submit the ajax call rewrites the view and the select fields lose their "chosen" functionality. How can we trigger the chosen jquery after the view ajax call?
Thanks,
Scott
Comment | File | Size | Author |
---|---|---|---|
#31 | apply-chosen-after-ajax-also-2023727-31.patch | 2.58 KB | maxocub |
#29 | apply-chosen-after-ajax-also-2023727-29.patch | 2.58 KB | maxocub |
| |||
#19 | apply-chosen-after-ajax-also-2023727-19.patch | 2.58 KB | OwilliwO |
Comments
Comment #1
Hydra CreditAttribution: Hydra commentedHm not exactly sure what you did there. I tryed using a simple view, added an exposed filter wich uses select. Enabeld ajax_load and autosubmit on exposed forms. Everything worked well.
Could you please provide some more detailed info? Perheps an export of a simple view, showing your problem would help me reproduce it.
Comment #2
duckydan CreditAttribution: duckydan commentedThis is not just ajax. Here is my issue:
http://dev.chattlibrary.org/calendar-node-field-event-date/month
If you pick a month and apply it, then go an pick another month, it reverts to the first month you picked most of the time.
I tried updating to the dev version of the module and the latest chosen library just in case that as it. No dice.
Dan
Dan
Comment #3
duckydan CreditAttribution: duckydan commentedOK, my issue seems to be the caching. If I turn off caching for the view, this seems to stop the issue.
Hope that helps someone.
Comment #4
Hydra CreditAttribution: Hydra commentedCan you try if the caching is a problem when not using chosen, too? I think that would be helpful, because it would be a views bug then. Otherwise I would rename this issue to something like "views cache compatibily" or I don't know :/ Sounds ugly :D
Comment #5
junedkazi CreditAttribution: junedkazi commentedI just checked the page in the link above on chrome and it is working fine for me. Did u disable the cache ??
Comment #6
duckydan CreditAttribution: duckydan commentedThe issue was also present without chosen. Sorry, I jumped to thew wrong conclusion.
Comment #7
Hydra CreditAttribution: Hydra commentedOkay, since this issue does not exists, I think we can mark this as "fixed" :)
If however this issue returns and somehow can be related to chosen, please reopen.
Comment #9
beardedgeek CreditAttribution: beardedgeek commentedCould I suggest this is reopened as this is still happening for me.
If I have ajax enabled, cache disabled, when I hit apply all the select lists revert to standard styling.
Comment #10
areynolds CreditAttribution: areynolds commentedI've been experiencing this issue with 7.x-2.x-dev; after submitting on the exposed Views filter, the filters refresh via AJAX and return filters that aren't styled by Chosen.
Investigating a bit further.
Comment #11
creatile CreditAttribution: creatile commentedI have the same issue. Is anyone found a solution ?
Comment #12
diamondseaI am also having this problem.
Create a block view using Ajax and a Select box as an exposed filter. When "Apply" is clicked to rerun/apply the exposed filter, the block is redrawn, including the Select box, which no longer has Select applied.
We need to re-fire the Chosen() function on the reload of the block somehow.
Comment #13
diamondseaThis is hackish, but it works to at least address this on my particular page. In my .../themename/js/script.js file, I added the following function
What it does:
1. On page load completion
2. It checks to see if it is the page I have my Views Block w/ Ajax and Exposed Filter
3. If so, it attaches to all ajaxComplete events on the page (of which the block view refresh will be one)
4. And re-applies the Chosen() call to all selects (add more specific selectors if needed)
What it probably should do:
- Attach to only the views blocks' Ajax calls.
- Use the Chosen module's defined selection rules
- Use the other Chosen module's settings (width, labels, etc)
- Be integrated into the Chosen module
I must unfortunately leave those steps to those without a fast-approaching deadline (and who are more fluent in proper Drupal module updating than I), but at least it should provide a workaround for people until then.
Comment #14
Ajtis.pl CreditAttribution: Ajtis.pl commentedThanks @diamondsea
Only one small change in selectors and it works nice :)
Comment #15
glynster CreditAttribution: glynster commentedI have had no luck on my end adding the following tweak to our custom js.
We are using adv aggregate, as soon as we disable this the chosen theming remains after an ajax request.
When I inspect the code all hints of chosen have been completely removed.
Here is the snippet I used but no luck:
Also tried
No luck on either.
Any other ideas?
Comment #16
glynster CreditAttribution: glynster commentedOK my issue was caused by the Form Placeholder module. Once I excluded the form class the problem was resolved.
Comment #17
madhukarkr CreditAttribution: madhukarkr commentedI am somehow missing chosen. I have created a view and kept taxonomy terms in exposed filters as dropdown list. I surely have more than 20 options in drop down. I have placed required library files at /sites/all/libraries/chosen/chosen and version is 1.1.0. I don't know why but am not getting select list modified. what am I missing here?
Comment #18
madhukarkr CreditAttribution: madhukarkr commentedGot it...my bad! i did not give the required settings for apply chosen. In my content type-> settings for taxonomy-> Apply Chosen to the select fields in this widget? here select apply and you are ready to go :)
Comment #19
OwilliwOHi guys,
I currently have the same problems.
I've exposed term filter, with AJAx enable, and chosen on term lists..
When i select one term and click Apply, chosen feature disappear and filter are only simple select list.
Here is a little patch on chosen.js, in which i wrap chosen acitvation in a function called two times : on page load and after ajax complete.
Have a look and tell me if it's OK.
Comment #20
zmove CreditAttribution: zmove commented#19 works well for me.
Comment #22
erozqba CreditAttribution: erozqba commentedThe patch #19 work well in Version: 7.x-2.x-dev not in 7.x-2.0-alpha2.
Comment #23
erozqba CreditAttribution: erozqba commentedComment #24
Watergate CreditAttribution: Watergate at Sicse commentedThanks, the patch in #19 works for me.
Comment #25
drusims CreditAttribution: drusims as a volunteer commentedThe patch #19 works like a charm in latest version of chosen : 7.x-2.0-alpha4
Comment #26
OwilliwOHi.
I've been trying to understand why my patch is not valid.
When validating, they used chosen 2.0-alpha2, and I've created my patch for alpha4 version.
Plus, this patch still work with alpha5 version.
How can we make tests OK, and up with chosen current version ?
Comment #27
maxocub CreditAttribution: maxocub commentedComment #28
maxocub CreditAttribution: maxocub commentedComment #29
maxocub CreditAttribution: maxocub commentedTrying to re-upload the path to make the tests run on the right branch.
Comment #31
maxocub CreditAttribution: maxocub commentedSorry, still the same patch as #19, but we should not trigger the tests since there's no tests.
Comment #32
Neograph734Great, this also fixes an issue where different Drupal commerce product variations would loose the chosen attribute for properties (eg color).
Considering that many people confirmed the patch from #19 worked and this is the same patch and it still applies... I guess it is save to set this to RTBC.
Comment #33
cilefen CreditAttribution: cilefen commentedComment #34
nagy.balint CreditAttribution: nagy.balint commentedHi!
We have tested on a site, and also on simplytestme, and Unfortunately we could not reproduce this issue.
The views is indeed replaced completely after the ajax call, but the chosen stays.
Either way since the js is implemented in a behavior, that is supposed to be called on each ajax request again on the context, so in theory this should work fine.
I guess something on the affected sites simply break the behavior of chosen. Maybe they cause a js error, or some other way.
So likely the issue is in additional contribs or custom code.
Can someone reproduce this issue on simplytestme?
Comment #35
nagy.balint CreditAttribution: nagy.balint commentedI will have to close it as cannot reproduce unless we can figure out which other module interferes with the functionality, as it should work out of the box due the behaviors.
Comment #36
Neograph734It took me some time to reproduce, but I've found #32 not to be a bug indeed... at least to some point.
My chosen settings (admin/config/user-interface/chosen) were set to trigger for the following elements
body:not(.page-admin) select
. This worked great, removing chosen from all admin settings form (most of then are not built for it and become too wide or too narrow).The thing I suppose that is happeling, is that there was no body element in the AJAX content (just some div's). So the selector no longer matched and Chosen was not applied.
No one can ask if that is desired behavior or not (perhaps Chosen should look at the entire DOM and not just the 'new' part), but I leave that to the maintainers.
Comment #37
Neograph734I switched to 'needs work' because I believe this patch does not solve the issue and the maintainers might need to have another look at the behaviors.
Comment #38
nagy.balint CreditAttribution: nagy.balint commentedI think that the module only applies chosen to the markup that is replaced is "works as intended", as otherwise that would mean to apply chosen to elements where chosen is already applied.
If excluding all admin pages is not possible in any other way, then likely we need a new option in admin to be able to do so.
Related issues:
#2534756: Enable Chosen on admin page only
#2089987: Disable chosen on admin pages
Comment #39
nagy.balint CreditAttribution: nagy.balint commentedComment #40
andyg5000I was able to reproduce this when my chosen selectors used the class from the body tag. For example ".page-my-view select".
Since the AJAX response does not return the full page, the context to reapply chosen doesn't exits. Changing the selector to use markup that is returned fixed the issue ".views-exposed-form select".
Not sure if it's worth re-opening this one, but hopefully that helps pinpoint the issue for others.
Comment #41
andyg5000