Hello @shedev,
You can either add a custom validation for the Attachments filed to force user remove special characters:
fd.field('Attachments').validators.push({
name: 'Attachments Validation',
error: "remove special chatacters",
validate: function(value) {
const spch = /[!@#$%^()]+/;
for (let i = 0; i < value.length; i++) {
if (spch.test(value[i].name)) {
return false
}
return true
}
}
});
Or replace the Attachments field with a List or Library control. This way you can rename files when they are uploaded to a document library, using the code:
var listOrLibrary = 'SPDataTable1';
var docLibraryTitle = 'DocumentLibraryName';
var docLibraryId = '2afe31be-ac14-49db-a0a8-bf8724bc8487';
fd.control(listOrLibrary).$on('filesUploaded',
function(itemIds) {
//get document library by Title
var library = pnp.sp.web.lists.getById(docLibraryId);
//go through each uploaded Item Id and set field values
library.getListItemEntityTypeFullName().then(function(entityTypeFullName) {
var batch = pnp.sp.web.createBatch();
var currentName;
var uri;
for (var i = 0; i < itemIds.length; i++) {
//specify which fields to update and how
var itemId = itemIds[i];
library.items.getById(itemId).select('FileRef', 'Id').get().then(function(item) {
return item
}).then(function(item) {
uri = item.FileRef;
var fileID = item.Id;
filename = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf(".")).replace(/[`~!@#$%^&*()]/gi, '');
var nbatch = pnp.sp.web.createBatch();
library.items.getById(fileID).inBatch(nbatch).update({
FileLeafRef: filename
}, "*", entityTypeFullName)
nbatch.execute().then(function() {
fd.control(listOrLibrary).refresh();
});
});
}
});
});