Skip to content

Commit

Permalink
Merge pull request #1221 from HardluckHalvey/master
Browse files Browse the repository at this point in the history
PeoplePicker validation bugfix
  • Loading branch information
joelfmrodrigues committed Jun 23, 2022
2 parents 87bdb33 + 65d589d commit 1e0ab6c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/controls/peoplepicker/IPeoplePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export interface IPeoplePickerProps {
*
*/
onGetErrorMessage?: (items: IPersonaProps[]) => string | Promise<string>;
/**
* Prop to validate contents on blur
*/
validateOnFocusOut?: boolean;
/**
* Method to check value of People Picker text
*/
Expand Down
14 changes: 14 additions & 0 deletions src/controls/peoplepicker/PeoplePickerComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
this.validate(items);
}

/**
* On blur UI event
* @param ev
*/
private onBlur = (ev) => {
if (this.props.validateOnFocusOut)
this.validate(this.state.selectedPersons);
}


/**
* Returns the most recently used person
Expand Down Expand Up @@ -185,6 +194,10 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic

if (!result) {
this.validated(items);

this.setState({
errorMessage: undefined
});
return;
}

Expand Down Expand Up @@ -302,6 +315,7 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
itemLimit={personSelectionLimit || 1}
disabled={disabled || !!internalErrorMessage}
onChange={this.onChange}
onBlur={this.onBlur}
resolveDelay={resolveDelay} />
</div>
);
Expand Down

0 comments on commit 1e0ab6c

Please sign in to comment.