fd is a Form Manager that provides access to all events, containers, controls, fields, validators, and data of the form.
Whenever you want to manipulate your form, you must call the manager first.
// the form is ready
fd.spRendered(() => {
// and its fields are available to get/set
fd.field('Title').value = 'New Title';
});
On this page, you will find information about fd properties, methods, and events.
The global variable fd has the following properties:
Gets the URL of the SharePoint list view.
fd.source; // 'https://contoso.sharepoint.com/sites/Main/Lists/Projects/AllItems.aspx'
Returns an object that holds information about the current item and the SharePoint list.
//return all columns with values as an object
fd.spFormCtx.ListData
//return the SharePoint list ID as a string
fd.spFormCtx.ListAttributes.Id
Checks if the form is valid or not. The method returns a promise that is resolved when all form elements have been validated.
await fd.validate():
Gets an array of form validators. Can be used to add new ones. These validators are more complex than Field validators and are used to check that multiple fields have appropriate values. If the fields do not meet these criteria, the form will not submit.
// return form validators
fd.validators;
// add new form Validator
fd.validators.push({
name: 'MyCustomValidator',
error: 'Age must be 18 or over in order to subscribe',
validate: function(value) {
if (fd.field('Age').value < 18
&& fd.field('PaymentModel').value === 'Subscription')
return false;
return true;
}
});
The form validator function can also be asynchronous:
fd.validators.push({
name: 'MyCustomValidator',
error: 'This item is locked and cannot be modified anymore.',
validate: function() {
return new Promise(resolve => {
// make a request to SharePoint for checking the actual values of the current item.
window.setTimeout(() => {
resolve(false); // validation failed
// resolve(true) if validation passed
}, 500);
});
}
});
Gets language constants as an object. Can be used to set text for localization.
To change language constant, call the property inside fd.created event:
//how to change a message
fd.created(() => {
fd.messages.PlumsailForm_Submission_Success = 'Thank you!';
});
//all available messages:
fd.created(() => {
fd.messages.Captcha_Error = "Captcha is invalid."
fd.messages.DataTable_ColumnRequired = "This column is required"
fd.messages.DataTable_Filter_MultipleItemsSelected = "items selected"
fd.messages.DataTable_Filter_OneItemSelected = "item selected"
fd.messages.DataTable_Filter_SelectAll = "Select all"
fd.messages.Failure_AccessDenied = "You do not have permissions to perform this action."
fd.messages.Failure_General = "An error has occurred. Please check the browser console (F12)."
fd.messages.Failure_ItemNotFound = "An item was not found. It may have been deleted or renamed by another user."
fd.messages.FileOrFolderNameForbiddenSymbols = "Please enter a name that doesn't start or end with a dot and doesn't include any of these characters: \" * : < > ? / \\ |."
fd.messages.MaxLengthUrlValidator_Error = "The value of this field may not contain more than {0} characters."
fd.messages.MultiChoice_SpecifyOwnValue = "Specify your own value:"
fd.messages.PlumsailForm_CorrectErrors = "Oops! There seem to be some errors below:"
fd.messages.PlumsailForm_Error_AccessDenied = "You do not have permissions to this form"
fd.messages.PlumsailForm_Error_Unhandled = "Something went wrong. Try again later..."
fd.messages.PlumsailForm_Note = "Note"
fd.messages.PlumsailForm_Submission_Btn = "Return to the form"
fd.messages.PlumsailForm_Submission_Error = "An error has occurred while saving the form. Please check the console (F12)."
fd.messages.PlumsailForm_Submission_Success = "Thanks for submitting the form!"
fd.messages.RequiredValidator_Error = "This field is required."
fd.messages.SPAttachmentsField_FileAlreadyExists = "A file with the name '{0}' already exists. Please, rename the file and try again."
fd.messages.SPAttachmentsField_FileNameInvalid = "File names can't begin or end with a period, or contain any of these characters: / \\ < > : * \" ? | # %. Please, rename the file '{0}' and try again."
fd.messages.SPChoiceField_SpecifyOwnValue = "Specify your own value:"
fd.messages.SPDataTable_AddFile = "Create"
fd.messages.SPDataTable_AddFolder = "Create"
fd.messages.SPDataTable_AddNewItem = "New"
fd.messages.SPDataTable_Aggregations_AVG = "Average"
fd.messages.SPDataTable_Aggregations_COUNT = "Count"
fd.messages.SPDataTable_Aggregations_MAX = "Maximum"
fd.messages.SPDataTable_Aggregations_MIN = "Minimum"
fd.messages.SPDataTable_Aggregations_STDEV = "Std Deviation"
fd.messages.SPDataTable_Aggregations_SUM = "Sum"
fd.messages.SPDataTable_Aggregations_VAR = "Variance"
fd.messages.SPDataTable_ConfirmDelete = "Are you sure you want to delete the selected item(s)?"
fd.messages.SPDataTable_CreateFolderDialogTitle = "Create a folder"
fd.messages.SPDataTable_DataSourceNotConfigured = "Data source is not configured."
fd.messages.SPDataTable_Delete = "Delete"
fd.messages.SPDataTable_DropFilesText = "Drop here..."
fd.messages.SPDataTable_Edit = "Edit"
fd.messages.SPDataTable_EnterFileName = "Enter your file name"
fd.messages.SPDataTable_EnterFolderName = "Enter your folder name"
fd.messages.SPDataTable_Folder = "Folder"
fd.messages.SPDataTable_ListNotFoundError = "List does not exist."
fd.messages.SPDataTable_NewDOC = "Word document"
fd.messages.SPDataTable_NewFolder = "Folder"
fd.messages.SPDataTable_NewONE = "OneNote notebook"
fd.messages.SPDataTable_NewPPT = "PowerPoint presentation"
fd.messages.SPDataTable_NewVSDX = "Visio drawing"
fd.messages.SPDataTable_NewXSL = "Excel workbook"
fd.messages.SPDataTable_NewXSLForm = "Forms for Excel"
fd.messages.SPDataTable_NewXSLSurvey = "Excel survey"
fd.messages.SPDataTable_NoViewPermission = "You do not have permission to view this list."
fd.messages.SPDataTable_SaveError = "Unable to save data to {0}. {1}"
fd.messages.SPDataTable_Upload = "Upload"
fd.messages.SPDataTable_Uploading = "Uploading..."
fd.messages.SPFormDocumentTitle_Display = "Display form"
fd.messages.SPFormDocumentTitle_Edit = "Edit form"
fd.messages.SPFormDocumentTitle_New = "New item"
fd.messages.SPFormToolbar_Close = "Close"
fd.messages.SPFormToolbar_Edit = "Edit"
fd.messages.SPFormToolbar_Save = "Save"
fd.messages.SPFormToolbar_Saving = "Saving..."
fd.messages.SPLookupField_AddNewItem = "Add new item"
fd.messages.SPLookupField_NoDataFound = "No data found."
fd.messages.SPLookupField_NoDataFound_Add = "No data found. Do you want to add new item - '{0}'?"
fd.messages.SPTaxonomyField_DialogTitle = "Select : {0}"
fd.messages.SPThumbnailField_UploadAnImage = "Add an image"
fd.messages.SPUrlField_ClickToTest = "Click here to test"
fd.messages.SPUrlField_TypeAddress = "Type the Web address:"
fd.messages.SPUrlField_TypeDescription = "Type the description:"
fd.messages.SPUserField_EmailOnlyPlaceholder = "Enter email addresses..."
fd.messages.SPUserField_Group = "Group"
fd.messages.SPUserField_MultiPlaceholder = "Enter names or email addresses..."
fd.messages.SPUserField_NoDataFound = "No user or group was found."
fd.messages.SPUserField_SendEmail = "Send email"
fd.messages.SPUserField_SinglePlaceholder = "Enter a name or email address..."
fd.messages.SPUserField_WaitImgAlt = "This animation indicates the operation is in progress. Click to remove this animated image."
fd.messages.SPUser_Calendar_Busy = "Busy"
fd.messages.SPUser_Calendar_MeetingTimeAccessibility = "from {0} to {1}"
fd.messages.SPUser_Calendar_Oof = "Out of office"
fd.messages.SPUser_Calendar_Tentative = "Tentative"
fd.messages.SPUser_Calendar_WorkingElsewhere = "Working else where"
fd.messages.Uploading_Error = "An error has occurred while uploading the file."
});
Get or set the name of the exported PDF file.
//set file name to current item's Title
fd.pdfFileName = fd.field('Title').value;
Specifies various options for exported PDF file, such as paper size, margin, orientation, etc. More info about all the options here.
fd.pdfOptions = {
paperSize: 'A4',
landscape: true,
multiPage: true
};
fd has the following methods:
Gets data from all fields on the form. Can be also used to set multiple values at the same time.
// get data as an object
fd.data();
// set field values
fd.data({Field1: value1, Field2: value2});
Exports the current form to a PDF file. Accepts the following arguments:
file – a filename of the file.
options – options for the PDF file, such as paper size, margin, orientation, etc.
fd.exportToPDF('contacts-form', {
paperSize: 'A4',
landscape: false,
multiPage: true
});
Find more about PDF options in How to save form as PDF for printing.
The global variable fd has the following events:
Occurs prior to the form creation.
vueConfig passed as an argument to the handler is a configuration of the main vue-component. You can register your own child components. You can read more about it here.
Asynchronous event
Can return a Promise and the corresponding operation will not continue until the promise is resolved.
fd.beforeCreate((vueConfig) => {
console.log('beforeCreate');
console.log(vueConfig);
});
Occurs as soon as the form is created.
vue passed as an argument to the handler is a Vue instance of the form.
It is also available from fd variable this way: fd._vue
fd.created((vue) => {
console.log('created');
console.log(vue);
});
Occurs before mounting the vue-component to DOM.
vue passed as an argument to the handler is a Vue instance of the form.
It is also available from fd variable this way: fd._vue
Asynchronous event
Can return a Promise and the corresponding operation will not continue until the promise is resolved.
fd.spBeforeRender((vue) => {
console.log('beforeRender');
console.log(vue);
});
Occurs after mounting the vue-component to DOM.
Best place to run your JavaScript since all elements are mounted.
vue passed as an argument to the handler is a Vue instance of the form.
It is also available from fd variable this way: fd._vue
fd.spRendered((vue) => {
console.log('rendered');
console.log(vue);
});
Occurs before submitting the form.
spForm passed as an argument to the function is a SharePoint client form.
Here, you can modify the form’s data with code before sending it to the server.
Asynchronous event
Can return a Promise and the corresponding operation will not continue until the promise is resolved.
fd.spBeforeSave((spForm) => {
console.log('spBeforeSave');
console.log(spForm);
});
//async check
fd.spBeforeSave(() => {
return new Promise(function(resolve, reject) {
// do something async
resolve();
});
});
//async check with pnpjs
fd.spBeforeSave(() => {
return pnp.sp.web.lists.getByTitle('FieldTestList').items.getById(1).get().then(function(item) {
console.log(item);
if(item.Title == fd.field('Title').value) {
throw new Error('Title is invalid!');
}
});
});
// modify a field value before submission
fd.spBeforeSave(() => {
fd.field('Status').value = 'Submitted';
});
Occurs after the data is submitted.
Can be used to display confirmation messages after the form is saved or perform some other actions.
result passed as an argument to the function. It is an object that contains additional fields of the SharePoint item:
Id — returns the ID of the item.
FileLeafRef — returns the name of the document or document set.
RedirectUrl — holds the URL of a page where a user will be redirected after saving. This field can be changed. RedirectUrl is ignored inside a panel.
KeepPanelOpened — if set to true, the form panel stays opened after saving the SharePoint item. By default, the property is set to false
fd.spSaved((result) => {
console.log('spSaved');
//log item ID
console.log(result.Id);
});
//prevent redirection on save
fd.spSaved((result) => {
result.RedirectUrl = null;
});
//prevent form panel from closing
fd.spSaved((result) => {
result.KeepPanelOpened = true;
});