sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Rename IPropertyPaneTextFieldProps.onGetErrorMessage to IPropertyPaneTextFieldProps.GetValidationMessage

Open vman opened this issue 10 years ago • 4 comments

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 "";
    }
  }

vman avatar Aug 27 '16 14:08 vman

Agree, the name of the method assumes an error happened :)

levalencia avatar Sep 18 '16 23:09 levalencia

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.

wictorwilen avatar Sep 19 '16 06:09 wictorwilen

OnValidation seems to be the correct one.

levalencia avatar Sep 19 '16 20:09 levalencia

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

msft-github-bot avatar Jan 30 '20 12:01 msft-github-bot