Skip to content

Conversation

@ValerasNarbutas
Copy link
Contributor

…ld collection.

Q A
Bug fix? [x]
New feature? [ ]
New sample? [ ]
Related issues? fixes #1986

What's in this Pull Request?

This pull request addresses a critical bug in the DynamicForm control that causes crashes when SharePoint's custom body formatting references field display names that no longer exist in the current field collection.

Problem

The DynamicForm control crashes when:

  • A section contains fields that have been deleted or renamed
  • SharePoint's custom formatting references non-existent field display names
  • The control attempts to render fields that are no longer available in the field collection

Solution

Added additional filtering logic to ensure only valid fields are processed and rendered:

  1. Section-level filtering: Sections are only rendered if they contain at least one valid field that exists in the current field collection
  2. Field-level filtering: Within each section, only fields that actually exist in the field collection are rendered
  3. Graceful degradation: The control now handles missing fields gracefully, matching SharePoint's default behavior

Changes Made

  • Enhanced the existing filter condition in DynamicForm.tsx to include field existence validation
  • Added field validation before rendering individual fields within sections
  • Ensures the control won't crash when fieldCollection.find() returns undefined

Impact

  • Fixes: Prevents crashes when custom formatting references deleted/renamed fields
  • Improves: Stability and reliability of the DynamicForm control
  • Maintains: Backward compatibility with existing implementations
  • Aligns: Behavior with SharePoint's out-of-the-box form handling

@AJIXuMuK AJIXuMuK merged commit cb7ce34 into pnp:dev Jul 19, 2025
1 check passed
@AJIXuMuK AJIXuMuK added this to the 3.22.0 milestone Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants