Last active
February 14, 2017 11:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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