question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic Form: add children to override field rendering

See original GitHub issue

Category

[x] Enhancement [ ] Bug [ ] Question

Version

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

Expected / Desired Behavior / Question

Currently, the DynamicForm does not allow for overriding individual fields. So you get the form as is. If you want one field to behave differently, you have to write the entire form yourself. I would like to suggest that you can add children to the DynamicForm for the fields that you want to render yourself. Let’s say you have a list with three fields: Title, SomeTextField and SomeOtherField and you want to do custom rendering for SomeOtherField, the you could put in a DynamicForm like this:

<DynamicForm 
          context={this.props.context} 
          listId={"3071c058-549f-461d-9d73-8b9a52049a80"}  
          listItemId={1}
          onCancelled={() => { console.log('Cancelled') }}
          onBeforeSubmit={async (listItem) => { return true; }}
          onSubmitError={(listItem, error) => { alert(error.message); }}
          onSubmitted={async (listItemData) => { console.log(listItemData); }}>
          <SomeCustomFieldComponent internalFieldName="SomeOtherField" /> //Other Properties can be added as well
</DynamicForm>

In the render function of the DynamicForm, you can check in the map whether the children of the component contains a child with the specified internalFieldName, if so, that child (in this case SomeCustomFieldComponent) is rendered, if not, nothing changes and the DynamicField is rendered. This need to be worked out in more detail, but I’d be happy to check if this can be implemented properly and to submit a pull request for this.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
martinlingstuylcommented, Nov 8, 2022

Hi @rakeshrelan118 , @bjdekker has planned to create an example blog on this.

Basically it can be set up as follows:

const fieldOverrides = {
  "FieldInternalName1": (fieldProperties: IDynamicFieldProps) => <>some-ui</>,
  "FieldInternalName2": (fieldProperties: IDynamicFieldProps) => <>some-ui</>
};

<DynamicForm 
  listId={someListId}
  webAbsoluteUrl={someSiteUrl} 
  context={spfxContext} 
  fieldOverrides={fieldOverrides}
/>

I believe you can use the fieldProperties to update the value of the field that should be submitted.

1reaction
martinlingstuylcommented, Aug 16, 2022

Great idea @bjdekker, can’t wait to try this out somewhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Salesforce Dynamic Forms: Overview & Deep Dive Tutorial
The premise of Dynamic Forms is to create user centric, intuitive page layouts that display the right information at the right time. Over...
Read more >
Add and Remove Form fields dynamically with React and ...
In this article, we will learn how we can add and remove form input fields dynamically. We will use react functional components to ......
Read more >
How to Dynamically Modify Forms Using Form Events - Symfony
To do this, you can rely on Symfony's EventDispatcher component system to analyze the data on the object and modify the form based...
Read more >
Creating Dynamic Forms With React Hooks - Aaron Powell
So in this post, we'll break down how you can make dynamic forms in React, including how to do conditional control over fields...
Read more >
Best way to render a parent fields and childrens fields in a ...
What you'll want to do is: create a modelchoicefield in the form and set the queryset to Child.objects.none().
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found