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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

donquixote’s picture

And yes, that's a lot of html for one form element :)

office@w3k.at’s picture

I too ran into this problem with a bootstrap sub theme.
Here is a patch replacing children() with find() in commerce shipping jQuery selector.

torgosPizza’s picture

Status: Active » Needs review
googletorp’s picture

Status: Needs review » Closed (won't fix)

I'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.