Within this series of posts about creating forms using the SharePoint Framework, I will go through the following steps:

So far in this series of posts we got the clickable zone that creates a form by calling the completeForm method but we haven’t actually put the completeform method together yet.

So first of all I’m creating a method. I’m passing in a parameter so that I can use this method for both the editing of existing items ( I’ll set the parameter to the selected item ) or I can use this method to create new items if I want to create a new item.

[code lang=text]
private _completeForm(myParamVar) {


Before I can use my form classes I need to do some imports:

[code lang=text]
import Form from ‘./Controls/form’;
import FormDropdownControl from ‘./Controls/formDropdownControl’;
import FormPeopleDropdownControl from ‘./Controls/formPeopleDropdownControl’;
import FormDateControl from ‘./Controls/formDateControl’;
import FormTextControl from ‘./Controls/formTextControl’;

Now finally we will get to the easy stuff: constructing the forms and the fields on the form.
I’m starting with the following two line in the completeForm method to create a form object

[code lang=text]
this._editForm = new Form();
this._editForm.formTitle = “Title”;

Then for each of my fields I need to include some lines to create my fields. For each field type this will be slightly different:

Text fields

First I’m starting with text fields simply creating a control of the FormTextControl type and adding the control to the from:

[code lang=text]
let title = new FormTextControl();
title.label = “Title”;
title.controlValue = “”;
title.placeHolder = “.title”;
title.cssId = “title”;

Date Fields

First I’m starting with date fields simply creating a control of the FormDateControl type and adding the control to the from:

[code lang=text]
let ForecastClose = new FormDateControl();
ForecastClose.label = “Forecast Close”;
ForecastClose.placeHolder = “.forecastclose”;
ForecastClose.cssId = “forecastclose”;


[code lang=text]
First I’m starting with dropdown fields simply creating a control of the FormDropdownControl type and adding the control to the from. One difference though is that I now need to set the available values of the drop down

let urgency = new FormDropdownControl();
urgency.label = “Urgency”;
urgency.placeHolder = “.urgency”;
urgency.cssId = “urgency”;
urgency.values = [“Low”, “Medium”, “High”];

People picker

Like with the dropdown control, with the people picker I will also need to set the available values. I’m going to query Office 365 for all the available users:

[code lang=text]
let personResponsible = new FormPeopleDropdownControl();
personResponsible.label = “Person Responsible”;
personResponsible.placeHolder = “.spResponsiblePerson”;
personResponsible.cssId = “spResponsiblePerson”;
console.log(“added person responsible”);

To populate the dropdown with all the people known to my Office 365 site I’m using the following lines:

[code lang=text]
.then((users: Users) => {
this._allUsers = users;


So now we need to implement a method _getListDataUsers to get all the users back:
this sounds more complicated than it is. Just one REST API call and the job is done:

[code lang=text]
public _getListDataUsers(): Promise {
return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + /_api/web/siteusers, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();

So now we have the form created and it’s aware of all the fields. Just one more thing to do and the form will appear. The form can be rendered by just including the following line:

[code lang=text]

How to create a form framework using SPFx in Office 365 and SharePoint Online Microsoft Office 365, Microsoft SharePoint, Microsoft SharePoint Online, SPFx or SharePoint Framework forms

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as a Principal Architect at HybrIT Services Ltd. You can contact me using contact@sharepains.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue Reading

%d bloggers like this: