Skip to content

Commit bd0edbd

Browse files
committed
Fix of #590 - showRequiredError prop is added
1 parent aecd5d5 commit bd0edbd

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

docs/documentation/docs/controls/PeoplePicker.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ The People picker control can be configured with the following properties:
6161
| personSelectionLimit | number | no | Defines the limit of people that can be selected in the control | 1 |
6262
| isRequired | boolean | no | Set if the control is required or not | false |
6363
| disabled | boolean | no | Set if the control is disabled or not | false |
64-
| errorMessage | string | no | Specify the error message to display | |
64+
| errorMessage | string | no | Specifies the error message to display if the the control is required and no items selected | |
65+
| showRequiredError | boolean | no | Specifies if the component should show mandatory field error message because of some changes occured in parent. Use this props (set to `true`), for example, when "Save" button on the form has been clicked | |
6566
| errorMessageClassName | string | no | applies custom styling to the error message section | |
6667
| showtooltip | boolean | no | Defines if need a tooltip or not | false |
6768
| tooltipMessage | string | no | Specify the tooltip message to display | |

src/controls/peoplepicker/IPeoplePicker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export interface IPeoplePickerProps {
5353
* Mandatory field error message
5454
*/
5555
errorMessage?: string;
56+
/**
57+
* Specifies if the component should show mandatory field error message because of some changes occured in parent
58+
*/
59+
showRequiredError?: boolean;
5660
/**
5761
* Method to check value of People Picker text
5862
*/

src/controls/peoplepicker/PeoplePickerComponent.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ export class PeoplePicker extends React.Component<IPeoplePickerProps, IPeoplePic
6363
}
6464
}
6565

66+
public componentWillReceiveProps(nextProps: IPeoplePickerProps) {
67+
if (this.props.showRequiredError !== nextProps.showRequiredError && nextProps.showRequiredError) {
68+
this.setState({
69+
showRequiredError: !this.state.selectedPersons || !this.state.selectedPersons.length
70+
});
71+
}
72+
}
73+
6674

6775
/**
6876
* Get initial persons

0 commit comments

Comments
 (0)