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

IPropertyPaneTextFieldProps does not have a way to set a default value

Open SPDoctor opened this issue 9 years ago • 6 comments

Category

  • [ ] Question
  • [ ] Typo
  • [ ] Bug
  • [x] Enhancement / Suggestion
  • [ ] Additional article idea

Expected or Desired Behavior

There should be a way to set a default value for a string field in the property pane within the web part code. Failing that the documentation for the PropertyPaneTextField should clearly direct the developer to use the manifest file, if that was the intention.

Observed Behavior

There is a 'value' field that seems to be intended for managing the value according to the documentation and is not intended as a way of setting a default (confirmed by testing). The documentation for the 'errorMessage' field suggests a default value field rather than a validation error message - could this be an error in the documentation typings file? Or was the intention to use web part configuration in the manifest (in which case the documentation is misleading)?

Steps to Reproduce

Create an SPFx webpart. Note that there is no programmatic way to set a default value for the PropertyPaneTextField other than implementing behaviour if the field is undefined.

SPDoctor avatar Jan 21 '17 14:01 SPDoctor

@SPDoctor , thanx for reporting. Known issue. We will try to get this fixed ASAP.

manishgarg1 avatar Jan 23 '17 04:01 manishgarg1

I have a quick question on this. Do you expect the default value to be stored in the backing property as soon as the property pane is loaded, or are you expecting the default value you provide to be more of a help text? just wondering if the right thing is to remove any reference to a default value, and just have the developer set the value of the field in the webpart itself. It would seem slightly strange to me to have a default value, but not have it be set until I display the property pane.

patmill avatar Jan 23 '17 18:01 patmill

I expected a default value to be set, either by the "value" property, or perhaps another property called something like "default", and that to be the value that appears until the user changes it. The fact that there is a value property, and the description of errorMessage lead you to think that. But I'm guessing the intention is that the default values are set in the web part manifest, not programmatically. I suggest either make it clear in the documentation that is what you are supposed to do, particularly the description of those properties I mentioned, OR have a default property that takes effect only when neither the user has set a value nor is there a value supplied in the manifest. The developer could code around this if the string is empty, but I think it is cleaner to do it explicitly through the API.

I wouldn't blame you if you chose to just update the documentation ;-)

SPDoctor avatar Jan 23 '17 22:01 SPDoctor

@SPDoctor - You are right here But I'm guessing the intention is that the default values are set in the web part manifest, not programmatically. As for the default value, whatever is set in the properties bag will be displayed on initial load.

and we will work on this and will be available in future releases - make it clear in the documentation that is what you are supposed to do, particularly the description of those properties I mentioned

srideshpande avatar Mar 02 '17 23:03 srideshpande

@SPDoctor - As said I have updated the documentation. It will be in production soon. Here is what it will read:

Value to be displayed in the text field when the value of the targetProperty in the manifest's property bag is empty or contains a null value.

I am closing the issue now. Please feel free to re-open it, if you think issue needs more attention from our end.

Thanks!

srideshpande avatar May 11 '17 22:05 srideshpande

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 29 '20 18:01 msft-github-bot