Manage Learn to apply best practices and optimize your operations.

Field validation for file upload control element

Here's a field validation for the File Upload Control element. I've only tried this where there is one Upload Control.

Here's a field validation for the File Upload Control element. I've only tried this where there is one Upload Control.

Copy the code below into the JSHeader event. I call the code from an action button's onClick event.

The code only allows for 1 file to be attached to a document. If a file already exists on the document, and another file is selected from the browse button, then the existing document is marked for deletion. This existing file is replaced with the newly selected file with no needed intervention from the user. Also the document can not be submitted until a file has been selected, or some smart user puts a '\' in the upload field.


function BOCRfile () { 
var doc=document.forms[0];
var pattern = /%%Detach.(d{1,4})/i;
var filepattern = //;
attachments = document.images.length;
goodFilename = "";

for ( var i=0; i < doc.length; i++ ) {
	if ( doc.elements[i].type=="file" ) {
		ULname = doc.elements[i].name;
		FPath=doc.elements[i].value;
		elemNum = i;
	}
	else if ( pattern.test ( doc.elements[i].name ) ) {
//		alert ( 'element name is: ' + doc.elements[i].name
 + ' - type is: ' + doc.elements[i].type + ' - value is: ' + 
doc.elements[i].value + ' - element #: ' + i );
		FileElemNum = i;
		doc.elements[FileElemNum].checked = true;
	}
}
if ( filepattern.test ( doc.elements[elemNum].value ) ) {
	goodFilename = "Y";
}

if ( ( attachments < 4 ) && ( FPath=="" ) ) { 
	msg1 = "You must attach the BackOrder Commit file to this document
 before clicking the Save and Close button.  ";
  	msg2 = "If you don't  want to save this document, click the 'Back'
 button.";
	alert ( msg1 + msg2 );
	doc.elements[elemNum].focus ();
	return false;
}
else if ( goodFilename=="" ) { 
	alert ( 'You have entered an invalid filename in the 'Browse' 
button field.  Please select the file again.' );
	doc.elements[elemNum].focus ();
	return false;
}
else { 
	if ( FPath=="" && doc.elements[FileElemNum].checked ) { 
		doc.elements[FileElemNum].checked = false;
	}
		doc.submit ()
	}
}

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close