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.
Hi,
the AJAX recalculation of the shipping cost does not work with bootstrap theme.
(or, it does not work on my site, and I assume that bootstrap is the reason.)
Bootstrap renders an additional wrapper div around form elements. E.g.
<div class="control-group form-type-textfield form-item-customer-profile-shipping-commerce-customer-address-und-0-thoroughfare form-item">
<label for="edit-customer-profile-shipping-commerce-customer-address-und-0-thoroughfare" class="control-label">Address 1 <span class="form-required" title="This field is required.">*</span></label>
<div class="controls"> <input class="thoroughfare form-text required shipping-recalculation-processed" type="text" id="edit-customer-profile-shipping-commerce-customer-address-und-0-thoroughfare" name="customer_profile_shipping[commerce_customer_address][und][0][thoroughfare]" value="North-Willys-Straße 1" size="30" maxlength="128">
</div></div>
The selector in commerce_shipping.js, Drupal.behaviors.commerceShipping only finds the form elements if they are immediate children of the .form-item div.
$('[id^="edit-customer-profile-"] .form-item', context).children('.form-select, .form-text, .form-radio, .form-checkbox:not([name*="[commerce_customer_profile_copy]"])').filter(':not(.shipping-recalculation-processed)').addClass('shipping-recalculation-processed').change(function() {
return $.fn.commerceCheckShippingRecalculation();
});
This can be fixed by targeting child elements of any generation, not just the direct children:
$('[id^="edit-customer-profile-"] .form-item', context).each(function(){
$('.form-select, .form-text, .form-radio, .form-checkbox:not([name*="[commerce_customer_profile_copy]"])', this).filter(':not(.shipping-recalculation-processed)').addClass('shipping-recalculation-processed').change(function() {
return $.fn.commerceCheckShippingRecalculation();
});
});
I can produce a patch, if you agree with the general direction.
Comment | File | Size | Author |
---|---|---|---|
#2 | commerce_shipping-ignore_form_element_wrapper-2136155-2.patch | 1.43 KB | office@w3k.at |
Comments
Comment #1
donquixote CreditAttribution: donquixote commentedAnd yes, that's a lot of html for one form element :)
Comment #2
office@w3k.at CreditAttribution: office@w3k.at commentedI too ran into this problem with a bootstrap sub theme.
Here is a patch replacing children() with find() in commerce shipping jQuery selector.
Comment #3
torgosPizzaComment #4
googletorp CreditAttribution: googletorp as a volunteer commentedI've thought about this.
If a theme break our JS then that theme should fix it.
You can use hook_js_alter in the theme or on your site to swap the default commerce_shipping js file out with one that works for your custom markup.