CRM-15153 - Give forms a unique css class based on full class name
authorColeman Watts <coleman@civicrm.org>
Wed, 20 Aug 2014 19:37:10 +0000 (20:37 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 20 Aug 2014 20:58:15 +0000 (21:58 +0100)
27 files changed:
CRM/Core/Form.php
templates/CRM/Activity/Form/Search.tpl
templates/CRM/Activity/Form/Task/FileOnCase.tpl
templates/CRM/Admin/Form/Setting/Mapping.tpl
templates/CRM/Batch/Form/Entry.tpl
templates/CRM/Campaign/Form/Gotv.tpl
templates/CRM/Case/Form/Activity/LinkCases.tpl
templates/CRM/Contact/Form/Contact.tpl
templates/CRM/Contact/Form/Inline/Address.tpl
templates/CRM/Contact/Form/Relationship.tpl
templates/CRM/Contact/Form/Task/Email.tpl
templates/CRM/Contact/Form/Task/PDFLetterCommon.tpl
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Form/SoftCredit.tpl
templates/CRM/Core/I18n/Form.tpl
templates/CRM/Event/Form/ManageEvent/EventInfo.tpl
templates/CRM/Event/Form/Participant.tpl
templates/CRM/Event/Form/ParticipantFeeSelection.tpl
templates/CRM/Event/Form/Registration/AdditionalParticipant.tpl
templates/CRM/Form/attachment.tpl
templates/CRM/Form/validate.tpl
templates/CRM/Mailing/Form/InsertTokens.tpl
templates/CRM/Member/Form/Membership.tpl
templates/CRM/Pledge/Form/Pledge.tpl
templates/CRM/SMS/Form/Provider.tpl
templates/CRM/Tag/Form/Tag.tpl
templates/CRM/common/pager.tpl

index 7307c84c3a74da0bdad136bf1b733165e43c8d0b..3fa2bed56f1a640b2257c7c50bba12b56185ace6 100644 (file)
@@ -170,6 +170,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       $this->_name = $name;
     }
     else {
+      // CRM-15153 - FIXME this name translates to a DOM id and is not always unique!
       $this->_name = CRM_Utils_String::getClassName(CRM_Utils_System::getClassName($this));
     }
 
@@ -187,6 +188,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     if (!isset(self::$_template)) {
       self::$_template = CRM_Core_Smarty::singleton();
     }
+    // Workaround for CRM-15153 - give each form a reasonably unique css class
+    $this->addClass(CRM_Utils_System::getClassName($this));
 
     $this->assign('snippet', CRM_Utils_Array::value('snippet', $_GET));
   }
@@ -646,6 +649,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $this->accept($renderer);
     $content = $renderer->toArray();
     $content['formName'] = $this->getName();
+    // CRM-15153
+    $content['formClass'] = CRM_Utils_System::getClassName($this);
     return $content;
   }
 
index c0fe4cbeccd997464cdf80cc15d73b92e72c63bf..fee095679f9f5508a0ff0982b917fad58711604b 100644 (file)
@@ -88,7 +88,8 @@
 {literal}
   <script type="text/javascript">
     CRM.$(function($) {
-      var roleId = $('input[name=activity_role]:checked', '#Search').val();
+      var $form = $('form.{/literal}{$form.formClass}{literal}'),
+        roleId = $('input[name=activity_role]:checked', $form).val();
       if (roleId) {
         $('.description .option-' + roleId).show();
       }
index 6049c453bc3440b2476540bdd4ae97465ed9f08a..ae3ae07e55f987f40b4b4554502568b5725e5ef8 100644 (file)
@@ -46,7 +46,7 @@
 {literal}
 <script type="text/javascript">
 CRM.$(function($) {
-  var $form = $("#{/literal}{$form.formName}{literal}");
+  var $form = $("form.{/literal}{$form.formClass}{literal}");
   $('input[name=unclosed_case_id]', $form).crmSelect2({
     placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
     minimumInputLength: 1,
index b48a52d6cc25c95d3aa290eb28cab1b81ca317a9..126af32277cff02a092f2f5458bba38f92bd19c2 100644 (file)
 {literal}
 <script type="text/javascript">
 CRM.$(function($) {
+  var $form = $('form.{/literal}{$form.formClass}{literal}');
   function showHideMapAPIkey() {
     var mapProvider = $(this).val();
     if ( !mapProvider || ( mapProvider === 'OpenStreetMaps' ) ) {
-      $('#Mapping tr.crm-map-form-block-mapAPIKey').hide( );
+      $('tr.crm-map-form-block-mapAPIKey', $form).hide( );
     } else {
-      $('#Mapping tr.crm-map-form-block-mapAPIKey').show( );
+      $('tr.crm-map-form-block-mapAPIKey', $form).show( );
     }
   }
   $('#mapProvider').each(showHideMapAPIkey).change(showHideMapAPIkey);
index a3bb2a852b5fee9b33f5ccd2b492931a0361f56b..f474ac0c37cbbaeb820d153c22689986f166a177 100644 (file)
 {literal}
 <script type="text/javascript">
 CRM.$(function($) {
+  var $form = $('form.{/literal}{$form.formClass}{literal}');
   $('.selector-rows').change(function () {
     var options = {
       'url': {/literal}"{crmURL p='civicrm/ajax/batch' h=0}"{literal}
     };
 
-    $("#Entry").ajaxSubmit(options);
+    $($form).ajaxSubmit(options);
   });
 
   $('#crm-container').on('keyup change', '*.selector-rows', function () {
index 6db4c0979c77ac8ff412d5712e473fcdefcdb58f..0d878054e29e09e239ab7953af166f0f564780c4 100755 (executable)
@@ -120,7 +120,7 @@ function loadVoterList( )
      var sourceUrl = {/literal}"{crmURL p='civicrm/ajax/rest' h=0 q='snippet=4&className=CRM_Campaign_Page_AJAX&fnName=voterList' }"{literal};
 
      var searchVoterFor = {/literal}'{$searchVoterFor}'{literal};
-     CRM.$( 'table.gotvVoterRecords', 'form#{/literal}{$form.formName}{literal}').dataTable({
+     CRM.$( 'table.gotvVoterRecords', 'form.{/literal}{$form.formClass}{literal}').dataTable({
                "bFilter"    : false,
     "bAutoWidth" : false,
         "bProcessing": true,
index 4d7217f735ea8e2e4794dfe9d8e6d6df762afb6e..3ba4dbeeae9baf50f22cd38e4ebd11e310e77694 100644 (file)
@@ -33,7 +33,7 @@
 {literal}
 <script type="text/javascript">
   CRM.$(function($) {
-    var $form = $("#{/literal}{$form.formName}{literal}");
+    var $form = $("form.{/literal}{$form.formClass}{literal}");
     $('input[name=link_to_case_id]', $form).crmSelect2({
       placeholder: {/literal}'{ts escape="js"}- select case -{/ts}'{literal},
       minimumInputLength: 1,
index 732830e129a1aedba2f028c6e68ae0bd8937f282..22b7acbde258de1f481105b4b472cbbe4e42d123 100644 (file)
 
   <script type="text/javascript" >
   CRM.$(function($) {
-    var $form = $("#{/literal}{$form.formName}{literal}");
+    var $form = $("form.{/literal}{$form.formClass}{literal}");
     var action = "{/literal}{$action}{literal}";
 
     $('.crm-accordion-body').each( function() {
index 7eeca293e6b58b7f257cf07bcf825e9ed95c7d0b..ff6a3ca3f0d79d13b584d849689851ecd97ce99d 100644 (file)
     }
   });
   {/literal}{* // Enforce unique is_primary fields *}{literal}
-  cj(':checkbox[id*="[is_primary"]', 'form#Address_{/literal}{$blockId}{literal}').change(function() {
+  cj(':checkbox[id*="[is_primary"]', 'form[name=Address_{/literal}{$blockId}{literal}]').change(function() {
     if (this.defaultChecked) {
       cj(this).crmError("{/literal} {ts escape='js'}Please choose another address to be primary before changing this one.{/ts}{literal}");
       cj(this).prop('checked', true);
     }
   });
   {/literal}{* // Reset location_type_id when cancel button pressed *}{literal}
-  cj(':submit[name$=cancel]', 'form#Address_{/literal}{$blockId}{literal}').click(function() {
+  cj(':submit[name$=cancel]', 'form[name=Address_{/literal}{$blockId}{literal}]').click(function() {
     var container = cj(this).closest('div.crm-inline-edit.address');
     var origValue = container.attr('data-location-type-id') || '';
     container.data('location-type-id', origValue);
index 9a234f6f0bd176d8cee44d86d4d612e576ab9787..4524998ce0ba0f544d0ef9afdc97f7badb32b604 100644 (file)
       {literal}
       CRM.$(function($) {
         var
-          $form = $("form#{/literal}{$form.formName}{literal}"),
+          $form = $("form.{/literal}{$form.formClass}{literal}"),
           relationshipData = {/literal}{$relationshipData|@json_encode}{literal};
         $('[name=relationship_type_id]', $form).change(function() {
           var
index acaf141d36a89ea6f3b3c9c7f5c8217d51e5dcf7..24b7aaf1fa3d96fff4413d8b5e8c51e4890bdeb1 100644 (file)
@@ -97,7 +97,7 @@
 
 {literal}
 CRM.$(function($) {
-  var $form = $("#{/literal}{$form.formName}{literal}");
+  var $form = $("form.{/literal}{$form.formClass}{literal}");
 
   $('.add-cc-link', $form).click(function(e) {
     e.preventDefault();
index 1fbf89818f8f58fdda640727b50d60a710a19d1c..64a9a2f155e438820974a06fb4ffbbb160fec22b 100644 (file)
 {literal}
 <script type="text/javascript">
 CRM.$(function($) {
-  var $form = $('form#{/literal}{$form.formName}{literal}');
+  var $form = $('form.{/literal}{$form.formClass}{literal}');
   $('#format_id', $form).on('change', function() {
     selectFormat($(this).val());
   });
index 9726b629fa5cfa16c50dc6d1c64231d9778aafbc..dbde692575d5ebdc83d1d3d293f75dc6076d7904 100644 (file)
       {literal}
       CRM.$(function($) {
 
-        var $form = $("#{/literal}{$form.formName}{literal}");
+        var $form = $("form.{/literal}{$form.formClass}{literal}");
         $("#contact_id", $form).change(checkEmail);
         checkEmail( );
 
index b9e762e6f9f4905daf89ced8e9d720edda333f4c..71dc72fdeafcaa653d4f221394f14c4047de43be 100644 (file)
@@ -67,7 +67,7 @@
 {literal}
 <script type="text/javascript">
   CRM.$(function($) {
-    var $form = $("#{/literal}{$form.formName}{literal}");
+    var $form = $("form.{/literal}{$form.formClass}{literal}");
     $('#showPCP, #showSoftCredit').click(function(){
       return showHideSoftCreditAndPCP();
     });
index 68f53f6e1693f34345e923a10078c638ac557f74..1749dab10c04f8c2e47173f9cf20e3d5abbac52b 100644 (file)
 <script type="text/javascript">
 var fieldName = "{/literal}{$field}{literal}";
 var tsLocale = "{/literal}{$tsLocale}{literal}";
-cj('#Form').submit(function() {
+var $form = $('form.{/literal}{$form.formClass}{literal}');
+cj($form).submit(function() {
       cj(this).ajaxSubmit({
                             beforeSubmit: function (formData, jqForm, options) {
                                                     var queryString = cj.param(formData);
-                                                    var postUrl     = cj('#Form').attr('action');
+                                                    var postUrl     = cj($form).attr('action');
                                                     cj.ajax({
                                                              type   : "POST",
                                                              url    : postUrl,
index a1980b18f760d71379ba634c8016543d85b8dcae..f180f7bf0ee7465ab6cd8e4546e05dd7932c9574 100644 (file)
 {literal}
 <script type="text/javascript">
   CRM.$(function($) {
-    $('#template_id', '#EventInfo').change(function() {
+    var $form = $('form.{/literal}{$form.formClass}{literal}');
+    $('#template_id', $form).change(function() {
       $('#crm-main-content-wrapper')
         .crmSnippet({url: CRM.url('civicrm/event/add', {action: 'add', reset: 1, template_id: $(this).val()})})
         .crmSnippet('refresh');
index e762821956266fa6d3a9bffc53b993f6cc7515ed..f04d976a2f9543be14eb3ec68c74641c239583c1 100644 (file)
     }
   );
 
-  cj('#Participant').on("click",'.validate',
+  cj('form[name=Participant]').on("click", '.validate',
     function(e) {
       var userSubmittedStatus = cj('#status_id').val();
       var statusLabel = cj('#status_id option:selected').text();
       {literal}
       CRM.$(function($) {
 
-        var $form = $('form#{/literal}{$form.formName}{literal}');
+        var $form = $('form.{/literal}{$form.formClass}{literal}');
 
         // don't show cart related statuses if it's disabled
         {/literal}{if !$enableCart}{literal}
index 50f84fb49cc6e425c237263b351f268ddbc011b8..60f0b9044fd861fa94da1769c9c60f5a27102170 100644 (file)
@@ -199,9 +199,10 @@ CRM.$(function($) {
 {literal}
 <script type='text/javascript'>
 CRM.$(function($) {
+  var $form = $('form.{/literal}{$form.formClass}{literal}');
   cj('.total_amount-section').remove(); 
 
-  cj('#ParticipantFeeSelection').submit(function(e) {
+  cj($form).submit(function(e) {
     var partiallyPaid = {/literal}{$partiallyPaid}{literal};
     var pendingRefund = {/literal}{$pendingRefund}{literal};
     var statusId = cj('#status_id').val();
index 147ece88a0ea9596ee871fc400e35c9cbfc7edf1..1e254c4de6b188212b0c9be1634aa63d9dbea1bf 100644 (file)
@@ -79,7 +79,7 @@
 
 function allowGroupOnWaitlist( participantCount, currentCount )
 {
-  var formId          = {/literal}'{$formId}'{literal};
+  var formId          = {/literal}'{$formName}'{literal};
   var waitingMsg      = {/literal}'{$waitingMsg}'{literal};
   var confirmedMsg    = {/literal}'{$confirmedMsg}'{literal};
   var paymentBypassed = {/literal}'{$paymentBypassed}'{literal};
index a15368d324763a1de07317ff3b76757a4a951555..f95f59ec8dbbc6bb8418f7a7e7c1e336ae1b4712 100644 (file)
     {literal}
     <script type="text/javascript">
       CRM.$(function($) {
-        var $form = $("#{/literal}{$form.formName}{literal}");
+        var $form = $("form.{/literal}{$form.formClass}{literal}");
         $form
           .on('click', '.crm-clear-attachment', function(e) {
             e.preventDefault();
index 852a2b7c2177c1d36df049b16b3625a12c69dc32..117867892ff2fba4a191818ca1b8650719862bf7 100644 (file)
 *}
 {* Initialize jQuery validate on a form *}
 {* Extra params and functions may be added to the CRM.validate object before this template is loaded *}
-{if !$crm_form_validate_included and $smarty.get.snippet neq 'json' and $form and $form.formName}
+{if !$crm_form_validate_included and $smarty.get.snippet neq 'json' and $form and $form.formClass}
   {assign var=crm_form_validate_included value=1}
   {literal}
   <script type="text/javascript">
     CRM.$(function($) {
-      $("#{/literal}{$form.formName}{literal}").crmValidate();
+      $("form.{/literal}{$form.formClass}{literal}").crmValidate();
     });
   </script>
   {/literal}
index cf5ebcd07ca9b52027687665da32b6d4c184ba45..9e6129463cb033e9d0ff42aef4467cf682ae634f 100644 (file)
@@ -29,7 +29,7 @@
 <script type="text/javascript" src="{$config->resourceBase}packages/jquery/plugins/jquery-fieldselection.js"></script>
 
 <script type="text/javascript">
-cj('form#{$form.formName}').data('tokens', {$tokens|@json_encode});
+cj('form.{$form.formClass}').data('tokens', {$tokens|@json_encode});
 var text_message = null;
 var html_message = null;
 var isPDF        = false;
@@ -352,7 +352,7 @@ CRM.$(function($) {
   }
 
   // Initialize token selector widgets
-  var form = $('#{/literal}{$form.formName}{literal}');
+  var form = $('form.{/literal}{$form.formClass}{literal}');
   $('input.crm-token-selector', form)
     .addClass('crm-action-menu')
     .change(insertToken)
index 0ff485622cbe4960da746f23d9090c488348308d..bc88ff4c1a1de62d0f8342576e86772ca98cff76 100644 (file)
     {if $context eq 'standalone' and $outBound_option != 2 }
     {literal}
     CRM.$(function($) {
-      var $form = $("#{/literal}{$form.formName}{literal}");
+      var $form = $("form.{/literal}{$form.formClass}{literal}");
       $("#contact_id", $form).change(checkEmail);
       checkEmail( );
 
     {literal}
     //keep read only always checked.
     CRM.$(function($) {
-      var $form = $("#{/literal}{$form.formName}{literal}");
+      var $form = $("form.{/literal}{$form.formClass}{literal}");
       var allowAutoRenew   = {/literal}'{$allowAutoRenew}'{literal};
       var alreadyAutoRenew = {/literal}'{$alreadyAutoRenew}'{literal};
       if ( allowAutoRenew || alreadyAutoRenew ) {
index 959321c54127e82f708b1c0aa262b3580c7cf400..0a390d443cbd5464205632a7d29ace60c45aa331 100644 (file)
@@ -237,7 +237,7 @@ function loadPanes( id ) {
     {if $context eq 'standalone' and $outBound_option != 2 }
     {literal}
     CRM.$(function($) {
-      var $form = $("#{/literal}{$form.formName}{literal}");
+      var $form = $("form.{/literal}{$form.formClass}{literal}");
       $("#contact_id", $form).change(checkEmail);
       checkEmail( );
 
index 6b0cc328ec0df257bb3421c498679497497ff48c..857130447f12eeca22505ed5c0819512ec7fc4f7 100644 (file)
@@ -77,7 +77,7 @@
 <script type="text/javascript" >
 {literal}
   CRM.$(function($) {
-    var $form = $("#{/literal}{$form.formName}{literal}");
+    var $form = $("form.{/literal}{$form.formClass}{literal}");
     $('select[name=name]', $form).change(function() {
       var url = {/literal}"{$refreshURL}"{literal} + "&key=" + this.value;
       $(this).closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet({url: url}).crmSnippet('refresh');
index 9dca5a9c279cc8df363617082d1479ceafe3dd90..52af9c8d3f3d9e35f324afaf4f1b034e6dd952c9 100644 (file)
@@ -38,8 +38,9 @@
 </style>
 <script type="text/javascript">
   (function($, _){{/literal}
-    var entityID={$entityID};
-    var entityTable='{$entityTable}';
+    var entityID={$entityID},
+      entityTable='{$entityTable}',
+      $form = $('form.{$form.formClass}');
     {literal}
     CRM.updateContactSummaryTags = function() {
       var tags = [];
@@ -51,7 +52,7 @@
         tags = tags.concat(setTags);
       });
       // contact summary tabs and search forms both listen for this event
-      $('#Tag').closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
+      $($form).closest('.crm-ajax-container').trigger('crmFormSuccess', {tabCount: tags.length});
       // update summary tab
       $("#contact-summary #tags").html(tags.join(', '));
     };
index 744d084c59d3fba23d77ee47d84a1675cc4fba61..4f56256b2d85689e6f1a7b92c9d240e46d1a2f8c 100644 (file)
@@ -48,8 +48,8 @@
     {* Controller for 'Rows Per Page' *}
     {if $location eq 'bottom' and $pager->_totalItems > 25}
      <div class="form-item float-right">
-       <label for="{$form.formName}-rows-per-page-select">{ts}Rows per page:{/ts}</label> &nbsp;
-       <input class="crm-rows-per-page-select" id="{$form.formName}-rows-per-page-select" type="text" size="3" value="{$pager->_perPage}"/>
+       <label for="{$form.formClass}-rows-per-page-select">{ts}Rows per page:{/ts}</label> &nbsp;
+       <input class="crm-rows-per-page-select" id="{$form.formClass}-rows-per-page-select" type="text" size="3" value="{$pager->_perPage}"/>
      </div>
      <div class="clear"></div>
     {/if}
@@ -60,7 +60,7 @@
         CRM.$(function($) {
           {/literal}
           var
-            $form = $('#{$form.formName}'),
+            $form = $('form.{$form.formClass}'),
             numPages = {$pager->_response.numPages},
             currentPage = {$pager->_response.currentPage},
             perPageCount = {$pager->_perPage},