Merge pull request #4380 from atif-shaikh/CRM-15301
[civicrm-core.git] / templates / CRM / Form / attachment.tpl
index d5df47513db26aa181688344bd2e72a121ece971..f95f59ec8dbbc6bb8418f7a7e7c1e336ae1b4712 100644 (file)
@@ -63,8 +63,8 @@
         {/if}
         <tr>
           <td class="label">{$form.attachFile_1.label}</td>
-          <td>{$form.attachFile_1.html}&nbsp;{$form.attachDesc_1.html}<a href="#" class="crm-hover-button" title="{ts}Clear{/ts}" onclick="clearAttachment( '#attachFile_1', '#attachDesc_1' ); return false;"><span class="icon close-icon"></span></a><br />
-            <span class="description">{ts}Browse to the <strong>file</strong> you want to upload.{/ts}{if $maxAttachments GT 1} {ts 1=$maxAttachments}You can have a maximum of %1 attachment(s).{/ts}{/if} {ts 1=$config->maxFileSize}Each file must be less than %1M in size. You can also add a short description.{/ts}</span>
+          <td>{$form.attachFile_1.html}&nbsp;{$form.attachDesc_1.html}<a href="#" class="crm-hover-button crm-clear-attachment" style="visibility: hidden;" title="{ts}Clear{/ts}"><span class="icon close-icon"></span></a>
+            <div class="description">{ts}Browse to the <strong>file</strong> you want to upload.{/ts}{if $maxAttachments GT 1} {ts 1=$maxAttachments}You can have a maximum of %1 attachment(s).{/ts}{/if} {ts 1=$config->maxFileSize}Each file must be less than %1M in size. You can also add a short description.{/ts}</div>
           </td>
         </tr>
         {if $form.tag_1.html}
@@ -84,7 +84,7 @@
             <tr class="attachment-fieldset"><td colspan="2"></td></tr>
             <tr>
                 <td class="label">{$form.attachFile_1.label}</td>
-                <td>{$form.$attachName.html}&nbsp;{$form.$attachDesc.html}<a href="#" class="crm-hover-button" title="{ts}Clear{/ts}" onclick="clearAttachment( '#{$attachName}' ); return false;"><span class="icon close-icon"></span></a></td>
+                <td>{$form.$attachName.html}&nbsp;{$form.$attachDesc.html}<a href="#" class="crm-hover-button crm-clear-attachment" style="visibility: hidden;" title="{ts}Clear{/ts}"><span class="icon close-icon"></span></a></td>
             </tr>
             <tr>
               <td class="label">{$form.$tagElement.label}</td>
   </div><!-- /.crm-accordion-wrapper -->
     {literal}
     <script type="text/javascript">
-      function clearAttachment( element, desc ) {
-        cj(element).val('');
-        cj(desc).val('');
-      }
+      CRM.$(function($) {
+        var $form = $("form.{/literal}{$form.formClass}{literal}");
+        $form
+          .on('click', '.crm-clear-attachment', function(e) {
+            e.preventDefault();
+            $(this).css('visibility', 'hidden').closest('td').find(':input').val('');
+          })
+          .on('change', '#attachments :input', function() {
+            $(this).closest('td').find('.crm-clear-attachment').css('visibility', 'visible');
+          });
+      });
     </script>
     {/literal}
  {/if} {* edit/add if*}