CRM-14882 - hide billing block for online contrib forms when total is zero. This...
[civicrm-core.git] / templates / CRM / Contribute / Form / Contribution / Main.tpl
index dfd3d1909903179cd22a9f8864e5dab74b9d5671..4bd752e2aa35643bf2365cfce5a5054e34d8b089 100644 (file)
   CRM.$(function($) {
     // highlight price sets
     function updatePriceSetHighlight() {
-      cj('#priceset .price-set-row').removeClass('highlight');
-      cj('#priceset .price-set-row input:checked').parent().parent().addClass('highlight');
+      cj('#priceset .price-set-row span').removeClass('highlight');
+      cj('#priceset .price-set-row input:checked').parent().addClass('highlight');
     }
     cj('#priceset input[type="radio"]').change(updatePriceSetHighlight);
     updatePriceSetHighlight();
+
+    function toggleBillingBlockIfFree(){
+       var total_amount_tmp =  $(this).data('raw-total'); 
+    // Hide billing questions if this is free
+           if(  total_amount_tmp == 0 ){
+               cj("#billing-payment-block").hide(); 
+           }else{
+               cj("#billing-payment-block").show(); 
+           }
+         }
+     CRM.$('#pricevalue').each( toggleBillingBlockIfFree);
+
+    $('#priceset input').on('change', function() {
+      CRM.$('#pricevalue').each( toggleBillingBlockIfFree);
+    });
   });
   {/literal}
 </script>