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.
It would be great to be able to toggle the chosen widget on admin pages.
This is already possible using the selector, but this doesn't work with Drupal's JS attach hooks. For example, when loading AJAX content chosen is not applied because the selector never applies to the new HTML.
A patch will follow.
Comment | File | Size | Author |
---|---|---|---|
#43 | chosen-toggle-admin-pages-option-2089987-43.patch | 1.74 KB | m.lebedev |
#40 | chosen-toggle-admin-pages-option-2089987-40.patch | 1.78 KB | abu-zakham |
#35 | Chosen-breaks-Views-module.png | 19.01 KB | ndf |
#32 | interdiff.2089987.29-32.txt | 1.1 KB | mvc |
#32 | chosen-toggle-admin-pages-option-2089987-32.patch | 1.8 KB | mvc |
Comments
Comment #1
klaasvw CreditAttribution: klaasvw commentedThe attached patch adds a variable for excluding chosen on admin pages.
Comment #2
klaasvw CreditAttribution: klaasvw commentedSetting status
Comment #3
klaasvw CreditAttribution: klaasvw commentedRemoved a syntax error from the patch.
Comment #4
klaasvw CreditAttribution: klaasvw commentedAdded another fix that prevents chosen being loaded by AJAX in the admin.
Comment #5
mxwitkowski CreditAttribution: mxwitkowski commentedTried applying the patch in #4 to both 7.x-2.0-alpha4 and 7.x-2.x-dev -- both failed:
patching file chosen.admin.inc
Hunk #1 FAILED at 51.
Comment #6
mvcI found it annoying to edit Views with Chosen enabled so I re-rolled (and simplified) this patch.
I renamed the variable because this option controls display on all admin pages and doesn't actually check if we're currently using whatever the current admin theme is (nor should it).
Comment #7
mxwitkowski CreditAttribution: mxwitkowski commentedApplied the patch to chosen 7.x-2.0-alpha3 and got a warning: Hunk #1 succeeded at 59 (offset 9 lines). The patch applied fine and all is working fine. @mvc -- nice work, thanks.
Comment #8
mvcright, i wrote the patch for the latest dev.
Comment #9
P2790 CreditAttribution: P2790 commentedCan this be committed to the latest dev?
Comment #10
mvcantonyanimator, mxwitkowski: if this patch works for you, please leave a comment saying so, and change the status of this issue to "reviewed & tested by the community" so that the maintainers know it's ready to go.
Comment #11
mxwitkowski CreditAttribution: mxwitkowski commented@mvc - confirmed, patch #6 is working well for me
Comment #12
mvcmxwitkowski : glad it worked!
if you think this is ready to be committed to the dev branch, please change the status to RTBC as explained here: https://drupal.org/node/156119
Comment #13
P2790 CreditAttribution: P2790 commentedThe patch is working for me too
Comment #14
zilla CreditAttribution: zilla commentedwould love to see this in an update - was using something like body:not(.page-admin) but seems clunky and as you may already know, it breaks imagecache (the default chosen settings)
Comment #15
millionleaves CreditAttribution: millionleaves commentedPatch works for me most of the time, but I've noticed it doesn't catch everything in Panels, e.g. when editing the settings for a Pane. Will note anything else that comes up.
Comment #16
idebr CreditAttribution: idebr commentedA path can be an admin path, but does not guarantee the current theme is actually the admin theme for example when a user is not allowed to view it. A common example is user/%user/edit, where administrators has a different theme than the user.
I suggest using a different approach that checks for the actual theme instead of the path.
Comment #17
mvc@idebr: that was the approach used in #4, but what if there is no admin theme set, or the admin theme is the same as the default theme? if you prefer to switch based on the theme, you'll have to check for those two cases and fall back to the test i used in #6. also, i think it's a mistake to remove the test for the path system/ajax.
Comment #18
mvcforgot to change status...
Comment #19
Mołot CreditAttribution: Mołot commentedI used patch from #6 and it works OK for me.
My suggestion: use the same approach as jQuery Update is now using, to determine admin pages. That way we will be able to keep things consistent.
The code used in #1524944 Allow different version for administrative pages is:
if (!empty($admin_version) && path_is_admin(current_path()))
Please, please stick to it for the consistency! I really don't want to end up with pages that have chosen enabled, but with jQuery version to low for chosen to work.
Comment #20
diamondseaRe #14: To make it work with the image styles without a patch, change the default selection string in "Apply Chosen to the following elements" to:
select:visible:not('.image-style-new select')
Comment #21
mvc@Mołot i agree with you that these modules should be consistent, and the test in my patch in #6 is exactly the same as jquery_update, except that here we also avoid loading chosen for system ajax callbacks which i think is the correct thing to do.
setting to 'needs review' again because i think i've answered idebr's objections in #17.
Comment #22
Dave ReidMisleading title
Comment #23
theapi CreditAttribution: theapi commented#6 works for me.
Thank you.
Comment #29
mike.davis CreditAttribution: mike.davis commentedI tried applying patch #16 to 7.x-2.0-beta4 but it failed with:
Hunk #1 FAILED at 181.
1 out of 1 hunk FAILED -- saving rejects to file chosen.module.rej
I have had a look at the bit that failed in chosen.module and I have updated it for this release and this seems to be working fine for me. From the comments, it could do with someone testing it with Panels. Views seems to be fine.
Comment #30
jenlamptonThis patch works for me with both views and panels. Nice work :)
Comment #31
Dave ReidShould this actually be a per-theme setting instead of just admin vs non-admin?
Comment #32
mvcI still disagree with the idea of testing based solely on the current theme, as mentioned in comment #17, so here's a patch which does both tests. I'm also proposing to disable this by default on admin pages -- opinions?
@Dave Reid, that would be more work and so far everyone commenting here just seems to want to control admin/non-admin. I suggest starting with this and waiting to see if there's a demand for finer control.
Comment #33
wOOge CreditAttribution: wOOge commentedWould it be useful to have an input box that lets you disable Chosen on either specified Drupal paths, or on specified css elements?
That way the module is not making broad decisions for the user, and the user can be very specific or be very general in their configuration.
Thoughts?
Comment #34
ndf CreditAttribution: ndf commentedPatch #32 does the job well. Not sure the default setting to disable on admin pages is logic.
@ Dave Reid and wOOge: to me the 'Disable Chosen on the following paths' approach seems most natural. On some admin-pages Chosen can be a great tool, on others (see attached image) it breaks. And yes, that would mean with this patch you first should enable Chosen on admin-pages :)
Comment #35
ndf CreditAttribution: ndf commentedComment #36
GuyPaddock CreditAttribution: GuyPaddock commentedThis still needs work... We're using Chosen on select lists in user profiles. When the user goes to edit his or her profile, Drupal considers the user edit page to be an "admin page" and therefore this patch causes Chosen not to work on that page unless we enable Chosen for ALL admin pages.
It seems like we do need a way to specify paths or permissions that control when Chosen should be applied. Just basing it on admin vs. non-admin doesn't seem correct. Perhaps it should also be based on whether the user has the permission to use the "admin theme"?
Comment #37
joelpittet@GuyPaddock
You can do this to help you out maybe?
Comment #38
lucsb CreditAttribution: lucsb commentedThis worked for me:
Place select#edit-selected in the Apply Chosen to the following elements text box in the module config page.
Comment #39
m.lebedev CreditAttribution: m.lebedev commentedRe #32:
current_path() == 'system/ajax'
This check causes problems when the form is updated using Ajax.
Example:
I propose to refuse this check.
Comment #40
abu-zakham CreditAttribution: abu-zakham at Vardot commentedHello, I have a case, need to disable chosen when admin edit node,
Note: admin theme is the same site theme.
I've rewrite patch #39 to fix it.
Thanks
Comment #42
m.lebedev CreditAttribution: m.lebedev commentedYour a new condition will break all sites. You can disable the chosen in your module, eg adding a hook_form_alter.
Comment #43
m.lebedev CreditAttribution: m.lebedev commentedfor new version chosen
Comment #45
nagy.balint CreditAttribution: nagy.balint commentedGoing to mark this as duplicate of #2534756: Enable Chosen on admin page only as that issue also contains this one.