Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #2768 by returning id on the Form.onChange handler #3173

Merged

Conversation

heath-freenome
Copy link
Member

Reasons for making this change

Fixed #2768 by improving the onChange callback on Form to return the id of the field experiencing the change

  • In @rjsf/utils, updated the FieldProps type for onChange to add an optional id: string parameter, making onChange for FieldTemplateProps use FieldProps definition
  • In @rjsf/core, updated the library to support returning an optional second parameter, id: string, to the onChange() prop on Form as follows:
    • Updated the Form.onChange() callback handler passed to all fields to take an optional third parameter, id: string, passing it out to the onChange() prop call
    • Updated ArrayField to make the callback returned from the onChangeForIndex() method take the additional id parameter and pass it along to the props.onChange() handler
    • Updated MultiSchemaField to make the onOptionChange() method pass along the this.getFieldId() value to the props.onChange() handler
      • Refactored the id logic for the select widget used in the MultiSchemaField into the getFieldId() method
    • Updated ObjectField to make the callback returned from the onPropertyChange() method take the additional id parameter and pass it along to the props.onChange() handler
    • Updated SchemaField to add a new handleFieldComponentChange() callback that ensures that an id is passed up the onChange callback chain
      • Updated the render of the FieldComponent to pass the handleFieldComponentChange() as the onChange handler
      • Updated all of the tests to check for the id in those situations when it is passed back - In @rjsf/playground, updated the onFormDataChange handler to log the id of the changed field if it is provided - Updated the form-props.md documentation to describe the new id parameter that may be returned - Upda
  • In @rjsf/playground, updated the onFormDataChange handler to log the id of the changed field if it is provided
  • Updated the form-props.md documentation to describe the new id parameter that may be returned
  • Updated the CHANGELOG.md accordingly

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

- In @rjsf/utils, updated the `FieldProps` type for `onChange` to add an optional `id: string` parameter, making `onChange` for `FieldTemplateProps` use `FieldProps` definition
- In @rjsf/core, updated the library to support returning an optional second parameter, `id: string`, to the `onChange()` prop on `Form` as follows:
  - Updated the `Form.onChange()` callback handler passed to all fields to take an optional third parameter, `id: string`, passing it out to the `onChange()` prop call
  - Updated `ArrayField` to make the callback returned from the `onChangeForIndex()` method take the additional `id` parameter and pass it along to the `props.onChange()` handler
  - Updated `MultiSchemaField` to make the `onOptionChange()` method pass along the `this.getFieldId()` value to the `props.onChange()` handler
    - Refactored the `id` logic for the select widget used in the `MultiSchemaField` into the `getFieldId()` method
  - Updated `ObjectField` to make the callback returned from the `onPropertyChange()` method take the additional `id` parameter and pass it along to the `props.onChange()` handler
  - Updated `SchemaField` to add a new `handleFieldComponentChange()` callback that ensures that an `id` is passed up the `onChange` callback chain
    - Updated the render of the `FieldComponent` to pass the `handleFieldComponentChange()` as the `onChange` handler
  - Updated all of the tests to check for the `id` in those situations when it is passed back
- In @rjsf/playground, updated the `onFormDataChange` handler to log the `id` of the changed field if it is provided
- Updated the `form-props.md` documentation to describe the new `id` parameter that may be returned
- Updated the `CHANGELOG.md` accordingly
@heath-freenome heath-freenome force-pushed the fix-2768-adding-id-to-onChange branch from 292706a to c1c16d5 Compare October 3, 2022 20:42
@heath-freenome heath-freenome merged commit 4adf86a into rjsf-team:main Oct 3, 2022
@heath-freenome heath-freenome deleted the fix-2768-adding-id-to-onChange branch October 3, 2022 21:09
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.

OnChange specific field
2 participants