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.

Is there a way to update outer formData from within a custom widget ?

See original GitHub issue

Prerequisites

Description

Right now, a widget can update only the field it’s associated with, using prop.onChange. I have a case, where one of the widgets is actually a google autocomplete address. This, requires emit or modify the formData, so that other fields such as city, state, zip can also be updated in formData; and thus, to make the widgets associated with them pick the relevant formData update, and fill in the value.

Version

Latest ^1.2.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
KKS1commented, Nov 8, 2020

Hi @OleksiL , here is a glimpse:

  1. Use uiSchema
uiSchema = {
      ......,
      'addressFieldName': {
         'ui:field': 'address'
      },      
....
}

where we have also, provided our RJSF Form, a set of custom fields and widgets that you want to register. E.g. in this case (simplified version)

const customFields = {
       ....,
       address: CustomAddress, // (this is your custom Address Field component, which will be registered within Form as `address` field),
       ...
}

Then,

<Form 
   fields={customFields}
   .....
   >
  1. For schema now, this will look like
schema = {
  ...,
 addressFieldName: {
   type: 'object',
   title: ' ',
   properties: {
     city: {
        type: 'string'
    },
    zip: {
        type: 'string'
    } 
  },
  ....
}
  1. formData will then contain an object addressFieldName which will then have city and zip strings underneath.

Hope it helps, cheers!

– kks1

1reaction
epicfaacecommented, Mar 28, 2019

Closing this issue, but feel free to repoen it if you have any additional questions!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a way to update outer formData from within a custom ...
Right now, a widget can update only the field it's associated with, using prop.onChange . I have a case, where one of the...
Read more >
Custom ui:widget will not alter the formData - Stack Overflow
You should hand down react-jsonschema-form's (FieldProps, if you are using typescript) onChange inside DefaultInput to the actual input field.
Read more >
Custom Widgets and Fields - React Jsonschema form
The API allows to specify your own custom widget and field components: A widget represents a HTML tag for the user to enter...
Read more >
Create a custom form widget that displays the populated values
This article provides information on how to create a custom form widget displaying populated values.
Read more >
Update Form Data Using the API - DevExtreme - DevExpress
If you need to update form data at runtime, redefine the formData object. In this case, form item values are updated automatically and...
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