I have managed to resolved the above mentioned issue.
The issue i was facing is because I had not rendered the Attachment
field for my custom form.
Refer below code for the same :
(function () {
var rows = {};
rows.one = '<tr>' +
'<td colspan="3">' +
'<table border="0" cellpadding="0" cellspacing="3">' +
'<tbody>' +
'<tr>' +
'<td>' +
'{{First_x0020_NameCtrl}}' +
'</td>' +
'<td>' +
'{{Middle_x0020_InitialCtrl}}' +
'</td>'+
'</tr>' +
'<tr class="labelRowBelow">' +
'<td>First Name<span class="required">*</span></td>' +
'<td>Middle Initial</td>' +
'</tr>' +
'</tbody>' +
'</table>' +
'</td>' +
'</tr>' +
'<tr><td>{{AttachmentsCtrl}}</td></tr>'; // is the the placeholder you need to add for the attachment
// Create object that have the context information about the field that we want to change it's output render
var formTemplate = {};
formTemplate.Templates = {};
formTemplate.Templates.View = function(ctx){
var formTable = "".concat('<table width="100%" cellpadding="5" id="idGFF">', rows.one, '</table>');
//Replace the placeholders with the default sharepoint controls
formTable = formTable.replace("{{First_x0020_NameCtrl}}", getSPFieldRender(ctx, "First_x0020_Name"));
formTable = formTable.replace("{{Middle_x0020_InitialCtrl}}", getSPFieldRender(ctx, "Middle_x0020_Initial"));
.....
.....
.....
.....
formTable = formTable.replace("{{AttachmentsCtrl}}", getSPFieldRender(ctx, "Attachments")); // this is to replace the placeholder for attachment with the attachment field's html.
return formTable;
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(formTemplate);
})();
//This function code set the required properties and call the OOTB (default) function that use to render Sharepoint Fields
function getSPFieldRender(ctx, fieldName)
{
var fieldContext = ctx;
var result = ctx.ListSchema.Field.filter(function( obj ) {
return obj.Name == fieldName;
});
fieldContext.CurrentFieldSchema = result[0];
fieldContext.CurrentFieldValue = ctx.ListData.Items[0][fieldName];
return ctx.Templates.Fields[fieldName](fieldContext);
}
After this modifications, try to use the attachment from the ribbon. it will work perfectly.