Skip to content

Commit 0b97b4b

Browse files
committed
Error message will be always displayed if validateOnLoad is set to true and there are invalid terms
1 parent f936742 commit 0b97b4b

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/controls/taxonomyPicker/ITaxonomyPicker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export interface ITaxonomyPickerState {
130130
openPanel?: boolean;
131131
loaded?: boolean;
132132
activeNodes?: IPickerTerms;
133+
invalidNodeIds?: string[];
133134
}
134135

135136
export interface ITermChanges {

src/controls/taxonomyPicker/TaxonomyPicker.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
111111
let isValidateOnLoad = validateOnLoad && initialValues && initialValues.length >= 1;
112112
if (isValidateOnLoad) {
113113

114-
let notFoundTerms: string[] = [];
114+
const notFoundTerms: string[] = [];
115+
const notFoundTermIds: string[] = [];
116+
115117
const termSet = await this.termsService.getAllTerms(termsetNameOrID, hideDeprecatedTags, hideTagsNotAvailableForTagging);
116118
const allTerms = termSet.Terms;
117119

@@ -120,12 +122,14 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
120122

121123
if (!allTerms.filter(t => t.Id === pickerTerm.key).length) {
122124
notFoundTerms.push(pickerTerm.name);
125+
notFoundTermIds.push(pickerTerm.key);
123126
}
124127
}
125128

126129
if (notFoundTerms.length) {
127130
this.setState({
128-
internalErrorMessage: strings.TaxonomyPickerTermsNotFound.replace('{0}', notFoundTerms.join(', '))
131+
internalErrorMessage: strings.TaxonomyPickerTermsNotFound.replace('{0}', notFoundTerms.join(', ')),
132+
invalidNodeIds: notFoundTermIds
129133
});
130134
}
131135
}
@@ -312,6 +316,23 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
312316
}
313317

314318
private validate = async (value: IPickerTerms): Promise<void> => {
319+
320+
//
321+
// checking if there are any invalid nodes left after initial validation
322+
//
323+
if (this.state.invalidNodeIds) {
324+
const changedInvalidNodeIds = this.state.invalidNodeIds.filter(id => {
325+
return !!value.filter(term => term.key === id).length;
326+
});
327+
328+
let internalErrorMessage = changedInvalidNodeIds.length ? this.state.internalErrorMessage : '';
329+
330+
this.setState({
331+
invalidNodeIds: changedInvalidNodeIds,
332+
internalErrorMessage: internalErrorMessage
333+
});
334+
}
335+
315336
if (this.props.errorMessage || !this.props.onGetErrorMessage) { // ignoring all onGetErrorMessage logic
316337
this.validated(value);
317338
return;

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,22 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
603603
<div className="ms-font-m">Services tester:
604604
<TaxonomyPicker
605605
allowMultipleSelections={true}
606-
termsetNameOrID="61837936-29c5-46de-982c-d1adb6664b32" // id to termset that has a custom sort
606+
//termsetNameOrID="61837936-29c5-46de-982c-d1adb6664b32" // id to termset that has a custom sort
607+
termsetNameOrID="8ea5ac06-fd7c-4269-8d0d-02f541df8eb9"
608+
initialValues={[{
609+
key: "c05250ff-80e7-41e6-bfb3-db2db62d63d3",
610+
name: "Business",
611+
path: "Business",
612+
termSet: "8ea5ac06-fd7c-4269-8d0d-02f541df8eb9",
613+
termSetName: "Trip Types"
614+
}, {
615+
key: "a05250ff-80e7-41e6-bfb3-db2db62d63d3",
616+
name: "BBusiness",
617+
path: "BBusiness",
618+
termSet: "8ea5ac06-fd7c-4269-8d0d-02f541df8eb9",
619+
termSetName: "Trip Types"
620+
}]}
621+
validateOnLoad={true}
607622
panelTitle="Select Sorted Term"
608623
label="Service Picker with custom actions"
609624
context={this.props.context}

0 commit comments

Comments
 (0)