Skip to content

Commit 287b069

Browse files
committed
Specifies if the initial values will be validated, when the component is loaded
1 parent 87af8a7 commit 287b069

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

docs/documentation/docs/controls/TaxonomyPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ The TaxonomyPicker control can be configured with the following properties:
164164
| anchorId | string | no | Set the anchorid to a child term in the TermSet to be able to select terms from that level and below. |
165165
| termActions | ITermActions | no | Allows to execute custom action on the term like e.g. get other term labelsITermActions. |
166166
| hideTagsNotAvailableForTagging | boolean | no | Specifies if the tags marked with 'Available for tagging' = false should be hidden |
167+
| validateOnLoad | boolean | no | Specifies if the initial values will be validated, when the component is loaded. Default value is false |
167168
| hideDeprecatedTags | boolean | no | Specifies if deprecated tags should be hidden |
168169
| placeholder | string | no | Short text hint to display in empty picker |
169170

src/controls/taxonomyPicker/ITaxonomyPicker.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { ExtensionContext } from '@microsoft/sp-extension-base';
99
* PropertyFieldTermPickerHost properties interface
1010
// */
1111
export interface ITaxonomyPickerProps {
12-
/**
13-
* Property field label displayed on top
14-
*/
12+
/**
13+
* Property field label displayed on top
14+
*/
1515
label: string;
1616
/**
1717
* TermSet Picker Panel title
@@ -79,6 +79,11 @@ export interface ITaxonomyPickerProps {
7979
*/
8080
placeholder?: string;
8181

82+
/**
83+
* Specifies if the initial values will be validated, when the component is loaded
84+
*/
85+
validateOnLoad?: boolean;
86+
8287
/**
8388
* The method is used to get the validation error message and determine whether the input value is valid or not.
8489
*

src/controls/taxonomyPicker/TaxonomyPicker.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
5454
this.onSave = this.onSave.bind(this);
5555
this.termsChanged = this.termsChanged.bind(this);
5656
this.termsFromPickerChanged = this.termsFromPickerChanged.bind(this);
57+
this.termsService = new SPTermStorePickerService(this.props, this.props.context);
58+
}
59+
60+
/**
61+
* componentDidMount lifecycle hook
62+
*/
63+
public componentDidMount() {
64+
this.validateTerms();
5765
}
5866

5967
/**
@@ -77,11 +85,34 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
7785
}
7886
}
7987

88+
/**
89+
* it checks, if all entries still exist in term store. if allowMultipleSelections is true. it have to validate all values
90+
*/
91+
private async validateTerms() {
92+
let isValidateOnLoad = this.props.validateOnLoad && this.props.initialValues != null && this.props.initialValues.length >= 1;
93+
if (isValidateOnLoad) {
94+
this.props.initialValues.forEach(async pickerTerm => {
95+
if (pickerTerm.termSet == null) {
96+
return;
97+
}
98+
99+
this.termsService.getAllTerms(pickerTerm.termSet, this.props.hideDeprecatedTags, this.props.hideTagsNotAvailableForTagging).then((response: ITermSet) => {
100+
let selectedTerms = response ? response : null;
101+
if (selectedTerms == null) {
102+
this.setState({
103+
errorMessage: `The selected term '${pickerTerm.name}' could not be found in term store.`
104+
});
105+
}
106+
});
107+
});
108+
}
109+
}
110+
80111
/**
81112
* Loads the list from SharePoint current web site
82113
*/
83114
private loadTermStores(): void {
84-
this.termsService = new SPTermStorePickerService(this.props, this.props.context);
115+
85116

86117
if (this.props.termActions && this.props.termActions.initialize) {
87118
this.props.termActions.initialize(this.termsService);

0 commit comments

Comments
 (0)