Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Last active February 14, 2017 11:49
Show Gist options
  • Select an option

  • Save chrisobriensp/d236c788a72f0a07e15fe04a1937fefb to your computer and use it in GitHub Desktop.

Select an option

Save chrisobriensp/d236c788a72f0a07e15fe04a1937fefb to your computer and use it in GitHub Desktop.
TypeScript to show a validation function for PropertyPaneTextbox in SPFX which makes an async call. See http://cob-sp.com/SPFx-WP-Props1
private asyncTextBoxValidationMethod(value: string): Promise<string> {
if (value !== undefined && value.length > 3) {
var url = this.context.pageContext.web.absoluteUrl + `/_api/web/lists?$filter=Hidden eq false`;
return this.fetchLists(url).then((response) => {
var lists: ISPList[] = response.value;
var foundList: boolean = false;
lists.forEach((list: ISPList) => {
if (value === list.Title) {
foundList = true;
}
});
if (!foundList) {
// resolve promise with error message to display..
return Promise.resolve("Value entered did not match a list in this site!");
}
// otherwise resolve promise with an empty string..
return Promise.resolve("");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment