Upload single attachments

Edoardo Gattei
Tera Expert

I have a widget to upload attachments (here's the HTML part) where I'm trying to force the user to be able to upload a single file at a time but it keeps taking multiple ... why?? 😞

 

<div ng-if="!no_attachments">

  <label class="field-label" title="${Attachments}" aria-label="${Attachments}">
    <span class="field-decorations">
      <span ng-show="mandatory_attachment" class="fa fa-asterisk mandatory ng-hide" ng-class="{'mandatory-filled': mandatory_filled()}" title="Required" style="padding-right: .25em" aria-label="Required " aria-hidden="true"></span>
    </span>
    ${Attachments}
  </label>

  <div class="text-center dashed panel panel-default panel-body sp-attachments" ng-file-drop="parent.attachmentHandler.onFileSelect($files)" ng-multiple="false">

    <div ng-if="uploading" class="sp-loading-indicator la-lg"> 
      <div></div> 
      <div></div> 
      <div></div> 
    </div>

    <div ng-hide="uploading">

      <i class="fa fa-cloud-upload fa-2x text-primary"></i>

      <div class="text-center text-italic text-muted">
        <em class="sp-drop-area">${Drop files here}</em> 
      </div>

      <div>${or}</div>

      <span class="file-upload-input">
        <input type="file" style="display: none" multiple="false" ng-file-select="parent.attachmentHandler.onFileSelect($files)" class="sp-attachments-input">
        <a href="javascript:void(0)" id="attachment_add" ng-click="parent.attachmentHandler.openSelector($event)" class="btn btn-primary sp-attachment-add" role="link">
          <i class="glyphicon glyphicon-paperclip"></i>
          <span>${Add attachment}</span>
        </a>
      </span> 

    </div>

    <div class="m-t-lg">  
      <!--<now-attachments-list template="sp_attachment_single_line" ></now-attachments-list>-->
      <tap_attachment-directive template="custom_entry"></tap_attachment-directive>
    </div>

  </div>

  <!--- remove the OOB attachment widget --->
  <style>
    div[ng-if="c.showAttachments()"] {
      display: none;
    }
    label[for="sp_formfield_sp_attachments"] {
      display: none;
    }
  </style>

</div>
2 REPLIES 2

JOE70
Kilo Contributor

you could add an onSubmit script to your catalog item, I have used this script many times to force an attachment count when i need it.

function onSubmit() {
	//Type appropriate comment here, and begin script below

var count = 1;
	
		
			if(window == null){

		if(this.document.getElementsByClassName('get-attachment').length != count) {
			g_form.addErrorMessage('Submit Only 1 attachmnet.');
			return false;
		}
	}
	
		
	

}

}

 

please mark helpful or correct 🙂

 

DanielCordick
Mega Patron
Mega Patron

Hi 

 

You could use an onSubmit script to do this. I have used this script many times to force an attachment count 

 

function onSubmit() {
	//Type appropriate comment here, and begin script below

var count = 1;
	
		
			if(window == null){

		if(this.document.getElementsByClassName('get-attachment').length != count) {
			g_form.addErrorMessage('You must add your attachment from  before submitting this request.');
			return false;
		}
	}
	
		
	

}

 

please mark helpful or correct