Rename IPropertyPaneTextFieldProps.onGetErrorMessage to IPropertyPaneTextFieldProps.GetValidationMessage
According to the docs, the onGetErrorMessage function is used to determine whether the value of a TextField in the property pane is valid or not. The function returns an error message if value is invalid and returns an empty string if value is valid.
In that case, should it be renamed to something else like GetValidationMessage which makes it clear that the function will return a validation message. The name onGetErrorMessage makes it sound like it will always return an error message.
Also, I don't think the property should start with the word "on". That makes it seem like the associated function would fire when an error message will be received. E.g. An onChange function fires when a change event occurs. Similarly, we expect onGetErrorMessage function to fire when an error message is received which is not the case here.
Here is my sample code:
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel,
onGetErrorMessage: this._validateDescription
})
private _validateDescription(value: string): string {
// If validation is not successful, return a string with error message.
if (value.length < 10) {
return "At least 10 characters required";
}
else {
// If validation is successful, return an empty string.
return "";
}
}
Agree, the name of the method assumes an error happened :)
While we're at it. It should not be named onGetErrorMessage. That assumes that we're expecting an event when we get the error message. Proper naming should bet onError or rather onValidation, ie it fires on validation.
OnValidation seems to be the correct one.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues