@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
import { PrimaryButton , DefaultButton , IconButton } from 'office-ui-fabric-react/lib/Button' ;
3
3
import { Panel , PanelType } from 'office-ui-fabric-react/lib/Panel' ;
4
4
import { Spinner , SpinnerSize } from 'office-ui-fabric-react/lib/Spinner' ;
5
+ import { Autofill } from 'office-ui-fabric-react/lib/components/Autofill/Autofill' ;
5
6
import { Label } from 'office-ui-fabric-react/lib/Label' ;
6
7
import TermPicker from './TermPicker' ;
7
8
import { IPickerTerms , IPickerTerm } from './ITermPicker' ;
@@ -32,6 +33,7 @@ export const TERM_IMG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQC
32
33
export class TaxonomyPicker extends React . Component < ITaxonomyPickerProps , ITaxonomyPickerState > {
33
34
private termsService : SPTermStorePickerService ;
34
35
private previousValues : IPickerTerms = [ ] ;
36
+ private invalidTerm : string = null ;
35
37
private cancel : boolean = true ;
36
38
37
39
/**
@@ -55,6 +57,9 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
55
57
this . onSave = this . onSave . bind ( this ) ;
56
58
this . termsChanged = this . termsChanged . bind ( this ) ;
57
59
this . termsFromPickerChanged = this . termsFromPickerChanged . bind ( this ) ;
60
+ this . onInputChange = this . onInputChange . bind ( this ) ;
61
+ this . onBlur = this . onBlur . bind ( this ) ;
62
+
58
63
this . termsService = new SPTermStorePickerService ( this . props , this . props . context ) ;
59
64
}
60
65
@@ -100,7 +105,6 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
100
105
* it checks, if all entries still exist in term store. if allowMultipleSelections is true. it have to validate all values
101
106
*/
102
107
private async validateTerms ( ) : Promise < void > {
103
-
104
108
const {
105
109
hideDeprecatedTags,
106
110
hideTagsNotAvailableForTagging,
@@ -140,8 +144,6 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
140
144
* Loads the list from SharePoint current web site
141
145
*/
142
146
private loadTermStores ( ) : void {
143
-
144
-
145
147
if ( this . props . termActions && this . props . termActions . initialize ) {
146
148
this . props . termActions . initialize ( this . termsService ) ;
147
149
// this.props.termActions.actions.forEach(x => {
@@ -275,6 +277,58 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
275
277
this . validate ( terms ) ;
276
278
}
277
279
280
+ /**
281
+ * Shows an error message for any invalid input inside taxonomy picker control
282
+ */
283
+ private validateInputText ( ) : void {
284
+ // Show error message, if any unresolved value exists inside taxonomy picker control
285
+ if ( ! ! this . invalidTerm ) {
286
+ // An unresolved value exists
287
+ this . setState ( {
288
+ errorMessage : strings . TaxonomyPickerInvalidTerms . replace ( '{0}' , this . invalidTerm )
289
+ } ) ;
290
+ }
291
+ else {
292
+ // There are no unresolved values
293
+ this . setState ( {
294
+ errorMessage : null
295
+ } ) ;
296
+ }
297
+ }
298
+
299
+ /**
300
+ * Triggers when input of taxonomy picker control changes
301
+ */
302
+ private onInputChange ( input : string ) : string {
303
+ if ( ! input ) {
304
+ const { validateInput } = this . props ;
305
+ if ( ! ! validateInput ) {
306
+ // Perform validation of input text, only if taxonomy picker is configured with validateInput={true} property.
307
+ this . invalidTerm = null ;
308
+ this . validateInputText ( ) ;
309
+ }
310
+ }
311
+ return input ;
312
+ }
313
+
314
+ /**
315
+ * Triggers when taxonomy picker control loses focus
316
+ */
317
+ private onBlur ( event : React . FocusEvent < HTMLElement | Autofill > ) : void {
318
+ const { validateInput } = this . props ;
319
+ if ( ! ! validateInput ) {
320
+ // Perform validation of input text, only if taxonomy picker is configured with validateInput={true} property.
321
+ const target : HTMLInputElement = event . target as HTMLInputElement ;
322
+ const targetValue = ! ! target ? target . value : null ;
323
+ if ( ! ! targetValue ) {
324
+ this . invalidTerm = targetValue ;
325
+ }
326
+ else {
327
+ this . invalidTerm = null ;
328
+ }
329
+ this . validateInputText ( ) ;
330
+ }
331
+ }
278
332
279
333
/**
280
334
* Gets the given node position in the active nodes collection
@@ -317,7 +371,6 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
317
371
}
318
372
319
373
private validate = async ( value : IPickerTerms ) : Promise < void > => {
320
-
321
374
//
322
375
// checking if there are any invalid nodes left after initial validation
323
376
//
@@ -389,7 +442,8 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
389
442
disabled,
390
443
isTermSetSelectable,
391
444
allowMultipleSelections,
392
- disabledTermIds, disableChildrenOfDisabledParents,
445
+ disabledTermIds,
446
+ disableChildrenOfDisabledParents,
393
447
placeholder,
394
448
panelTitle,
395
449
anchorId,
@@ -418,6 +472,8 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
418
472
value = { activeNodes }
419
473
isTermSetSelectable = { isTermSetSelectable }
420
474
onChanged = { this . termsFromPickerChanged }
475
+ onInputChange = { this . onInputChange }
476
+ onBlur = { this . onBlur }
421
477
allowMultipleSelections = { allowMultipleSelections }
422
478
disabledTermIds = { disabledTermIds }
423
479
disableChildrenOfDisabledParents = { disableChildrenOfDisabledParents }
0 commit comments