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

ArrayFieldItemTemplate errors are not getting resetting on remove and new addition #4435

Open
4 tasks done
DharamveerYadav opened this issue Jan 1, 2025 · 3 comments
Open
4 tasks done

Comments

@DharamveerYadav
Copy link

DharamveerYadav commented Jan 1, 2025

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

Currently error messages are not getting reset for ArrayFieldItemTemplate, If I have done validation and do removal and new addition.

Expected Behavior

Error messages should reset.

Steps To Reproduce

  1. go to this playground
{
  "definitions": {
    "Thing": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "default": "Default name"
        }
      }
    }
  },
  "type": "object",
  "properties": {
    "listOfStrings": {
      "type": "array",
      "title": "A list of strings",
      "items": {
        "type": "string"
      }
    }
  }
}
  1. add new row and click on validate
image
  1. now remove the last array item.
image
  1. Add new item again.
image

Ideally error message should not come again, if this is a new row. Basically schema is containing errors and not resetting remove and add operation.

Environment

- OS:
- Node:
- npm:

Anything else?

https://rjsf-team.github.io/react-jsonschema-form/

@DharamveerYadav DharamveerYadav added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jan 1, 2025
@heath-freenome
Copy link
Member

@DharamveerYadav If you turn on live validate (as provided in this playground), you'll see the validation errors going away using your steps. This is not a bug since validation is an active behavior that must be done on the form.

@heath-freenome heath-freenome added question awaiting response and removed bug needs triage Initial label given, to be assigned correct labels and assigned labels Jan 10, 2025
@DharamveerYadav
Copy link
Author

Hi @heath-freenome Thank you for your reply. My point is if we remove an errored out array item and add a new array item as mentioned in point number 5, It should create fresh or new array object, without any array.
live validation work if validate and fill the same field. here we are creating new array item.

@heath-freenome
Copy link
Member

Hi @heath-freenome Thank you for your reply. My point is if we remove an errored out array item and add a new array item as mentioned in point number 5, It should create fresh or new array object, without any array. live validation work if validate and fill the same field. here we are creating new array item.

@DharamveerYadav if you really want the error to go away on change, then simply use the liveValidation feature. Without turning on that feature, no validation re-occurs unless the user explicitly causes it to happen themselves (usually via the submit). Internally, the previous validation objects that were manually generated are based on index paths, so deleting and adding a new field satisfies that index path. So, unless you revalidate, the errors objects remain in the Form state, causing the error to be displayed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants