pnp / pnp/sp-dev-fx-controls-react

Dynamic Form Field Override Default value is not setting for single line of Text Column

Open
#2,049 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
433
Forks
418
Avg merge
5d 6m
Merged PRs (30d)
19

Description

Thank you for reporting an issue, suggesting an enhancement, or asking a question. We appreciate your feedback - to help the team understand your
needs please complete the below template to ensure we have the details to help. Thanks!

Please check out the documentation to see if your question is already addressed there. This will help us ensure our documentation is up to date.

Category

[ ] Enhancement

[x] Bug

[ ] Question

Version

Please specify what version of the library you are using: [3.21.0]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

When overriding a Single line of text field in a DynamicForm using fieldOverride, setting a default value should:

Show the value in the form when it renders (based on context, e.g. specific page).

Persist that value into the form model and save it to the list item when the form is submitted.

Observed Behavior

For Lookup columns, this works as expected — default values display and are saved.

For Single line of text columns (example: EntityID):

The default value shows in the UI.

But when saving, the field value is not included in the payload.

Even though we are calling onChanged in useEffect to commit the value, it is still not persisted.

Steps to Reproduce

Create a SharePoint list with a Single line of text field (EntityID).

Render a DynamicForm with a field override for this column.

Use code similar to:
const EntityIDOverride: React.FC<{ fieldProperties: IDynamicFieldProps; currentItem: any }> = ({
fieldProperties,
currentItem,
}) => {
const { columnInternalName, value, onChanged, ...rest } = fieldProperties;

const entityId = currentItem?.currentProperty?.EntityID
? String(currentItem.currentProperty.EntityID)
: '';

React.useEffect(() => {
if (entityId && !value) {
console.log('🔁 Committing EntityID default:', entityId);
onChanged?.(columnInternalName, entityId, true);
}
}, [entityId]);

return (
<DynamicField
{...rest}
columnInternalName={columnInternalName}
value={value ?? entityId}
newValue={value ?? entityId}
defaultValue={entityId}
onChanged={(col, val, validate, additional) => {
console.log('✏️ EntityID changed:', col, val);
onChanged?.(col, val, validate, additional);
}}
/>
);
};

EntityID: (props) => (

),

Load the form from a page where EntityID should be pre-populated.

Save the form.

Result:

Field shows the default value.

On save, the value is not persisted into the list item.

Submission Guidelines

Delete this section after reading

  • All suggestions, questions and issues are welcome, please let us know what's on your mind.
  • Remember to include sufficient details and context.
  • If you have multiple suggestions, questions, or bugs please submit them in separate issues so we can track resolution.

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the DynamicForm fieldOverride path and the DynamicField entry point, using the EntityIDOverride reproduction described in the issue. Check how the single-line text value reaches the form model and save payload, then verify that the default EntityID is both displayed and persisted when the form is submitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.