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.
In the hierarchical_select.js and this function:
Drupal.ajax.prototype.commands.hierarchicalSelectUpdate = function(ajax, response, status, hsid) {
// Replace the old HTML with the (relevant part of) retrieved HTML.
$('#hierarchical-select-'+ hsid +'-wrapper', Drupal.HierarchicalSelect.context)
.parent('.form-item')
.replaceWith($(response.output));
};
It uses parent('form-item'). The theme I am using, http://drupal.org/project/bootstrap, does not have the default HTML element hierarchy that the parent('form-item') expects. A simple fix would be to use parents('form-item') (select ancestors) or parents('form-item').first() (select the first ancestor).
What do you think? Is this a change that can happen?
Comment | File | Size | Author |
---|---|---|---|
#1 | hierarchical_select-js-fix-parent-to-closest.patch | 597 bytes | RobKoberg |
Comments
Comment #1
RobKoberg CreditAttribution: RobKoberg commentedBetter to use closest('form-item') instead of parents('form-item').first(). Patch is attached
Comment #2
generalredneckAwesome job.
Tested by the community.
Comment #3
bingorabbit CreditAttribution: bingorabbit commentedThat worked for me, Thanks a lot :)
Comment #4
mjs2020 CreditAttribution: mjs2020 commented#1 Worked for me too. Thanks RobKoberg!
Comment #5
Wim Leers1. Was this also tested with e.g. Bartik, to ensure it still works with other themes?
2. The correct solution seems to me to let the Hierarchical Select module add a class of its own.
The code looks sane, but it looks bizarre that what before was guaranteed to be the parent (first ancestor) now can be … any ancestor.
Comment #6
RobKoberg CreditAttribution: RobKoberg commentedThe jQuery closest function will find the first ancestor or self with the class name by traversing up the DOM hierarchy from the wrapper element (including the wrapper element). The way the current code is (using the parent function) is not appropriate because some themes (e.g. bootstrap) will create different HTML structures for the form-items and should not assume that the parent will always be the form-item.
http://api.jquery.com/closest/
I also want to look at using select2 for this interaction. Check out select2 to see if this could be an option. It provides an excellent UI similar to what you are currently providing:
http://ivaynberg.github.io/select2/
Comment #7
jOksanen CreditAttribution: jOksanen at Realityloop commentedThere is also an issue in some themes not having '.form-item' at all.
Comment #8
stefan.r CreditAttribution: stefan.r commentedIf anyone has a patch and can address #5, I'll be happy to have a look at it
Comment #9
GoldLooking at where the
$('#hierarchical-select-'+ hsid +'-wrapper', Drupal.HierarchicalSelect.context)
appears in the DOM the first.form-item
div also has a class ofform-type-hierarchical-select
.Switching to Bootstrap I see that
form-type-hierarchical-select
is present. However, I also see thatform-item
is also present.Is this still an issue? With no movement on this in 3 years I'm suspecting this is now outdated. I will mark it as such.
If this *is* still an issue please reopen it.