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

Missing uiSchema When TransformingErrors #3170

Closed
4 tasks done
Bedrock02 opened this issue Oct 3, 2022 · 5 comments · Fixed by #3358
Closed
4 tasks done

Missing uiSchema When TransformingErrors #3170

Bedrock02 opened this issue Oct 3, 2022 · 5 comments · Fixed by #3358

Comments

@Bedrock02
Copy link

Bedrock02 commented Oct 3, 2022

Prerequisites

What theme are you using?

core

Version

^4.2.4

Current Behavior

For required properties in a schema, we are unable to transform errors. Our transformer relies on attributes from the uiSchema to render a message with ui:title. The error AjvError provides the incorrect object, or will not provide the uiSchema at all.

Expected Behavior

  1. uiSchema provided by the AjvError object will always have the correct uiSchema
  2. uiSchema should reflect the current error

Steps To Reproduce

  1. Create a simple schema like so
schema: {
      title: 'Colors',
      type: 'object',
      required: ['favColor'],
      properties: {
        faveColor: {
          type: 'string',
          title: 'Enter your Favorite Color',
        }
      }
    },
uiSchema: {
      faveColor: {
        'ui:title': 'Favorite color'
      }
    }
  1. Create an RJSF Form and pass the schema and uiSchema into the form
  2. Provide a transformError function that takes in errors the current uiSchema
  3. Render the Form
  4. Attempt to submit the form with no data (or have liveValidate={true})

Environment

- OS: 12.1
- Node: v16.17.0
- npm: 8.15.0

Anything else?

https://jsfiddle.net/Bedrock02/06nu13gq/57/

@Bedrock02 Bedrock02 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Oct 3, 2022
@heath-freenome
Copy link
Member

@Bedrock02 since the transformError function and uiSchema are both passed to the Form you already have access to the uiSchema outside of the form. Can't you simply make sure that your transformError function is already using the uiSchema. If you need to you could so something like this:

const schema = { ... }; // Your schema
const uiSchema = { ... }; // Your uiSchema
function tranformHandler(errors) {
  return transformErrors(errors, uiSchema); // <- Your function that needs the uiSchema
}
...

<Form schema={schema} uiSchema={uiSchema} transformErrors={transformHandler} />

@heath-freenome heath-freenome added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Oct 10, 2022
@Bedrock02
Copy link
Author

Bedrock02 commented Oct 10, 2022

@heath-freenome did you get a chance to look at the jsfiddle I provided? I'm doing just that

// Here we are passing in the uiSchema to a closure function,
// Which returns a function that would take in those errors.

const transformErrors = (uiSchema) => {
  return (errors) => {
    return errors.map(error => {
      const propertyUiSchema = getUiSchemaFromProperty(error.property, uiSchema)

      const customError = generateCustomError(error, propertyUiSchema)
      if (customError) error.message = customError

      return error
    })
  }
}
// Used on the form
        <Form
          schema={schema}
          uiSchema={uiSchema}
          transformErrors={transformErrors(uiSchema)} 

@heath-freenome
Copy link
Member

heath-freenome commented Oct 10, 2022

@Bedrock02 so you have a bug in your jsfiddle... the property is faveColor but your required says favColor. Fixing that gives something that works, although it does things differently than what you expect

@Bedrock02
Copy link
Author

Thanks @heath-freenome. This issue smells like something is happening on our end. Will update once we figure this out.

@Bedrock02
Copy link
Author

@heath-freenome seems to be an error state race condition happening on load. It is only effecting required and no other validation rule. Since on render the input is set to an empty string, it will trigger an error.

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 8, 2023
Fixes rjsf-team#3170 by updating types and implementations to support passing `uiSchema` to the `validateFormData()` call so that it can be forwarded to `customValidate()` and `transformErrors()`
- In `@rjsf/utils`, updated the `ValidatorType` to take the `F` generic so that `validateFormData()` can be passed `uiSchema?: UiSchema<T, S, F>`
  - This required updating all of the schema-based functions to also take the `F` generic and properly adding generics to all the function calls
  - Also, the `CustomValidator` and `ErrorTransformer` types were updated to take all the generics needed to add the `uiSchema?: UiSchema<T, S, F>` parameter to the functions
- In `@rjsf/validator-ajv6`, updated the `customizeValidator` and `AJV6Validator` implementations to add the `S` and `F` generics
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/validator-ajv8`, updated the `customizeValidator` and `AJV8Validator` implementations to add the `F` generic
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/core`, updated the `ValidatorType`, `CustomValidator` and `ErrorTransformer` types to add the appropriate missing generics
  - Also passed `uiSchema` to the `validateFormData()` call
- Updated the `utility-functions.md` file to add the new generics
- Updated the `typescript.md` file to switch to using `customizeValidator()` with the generics to get the `validator`
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 8, 2023
Fixes rjsf-team#3170 by updating types and implementations to support passing `uiSchema` to the `validateFormData()` call so that it can be forwarded to `customValidate()` and `transformErrors()`
- In `@rjsf/utils`, updated the `ValidatorType` to take the `F` generic so that `validateFormData()` can be passed `uiSchema?: UiSchema<T, S, F>`
  - This required updating all of the schema-based functions to also take the `F` generic and properly adding generics to all the function calls
  - Also, the `CustomValidator` and `ErrorTransformer` types were updated to take all the generics needed to add the `uiSchema?: UiSchema<T, S, F>` parameter to the functions
- In `@rjsf/validator-ajv6`, updated the `customizeValidator` and `AJV6Validator` implementations to add the `S` and `F` generics
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/validator-ajv8`, updated the `customizeValidator` and `AJV8Validator` implementations to add the `F` generic
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/core`, updated the `ValidatorType`, `CustomValidator` and `ErrorTransformer` types to add the appropriate missing generics
  - Also passed `uiSchema` to the `validateFormData()` call
- Updated the `utility-functions.md` file to add the new generics
- Updated the `typescript.md` file to switch to using `customizeValidator()` with the generics to get the `validator`
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 8, 2023
Fixes rjsf-team#3170 by updating types and implementations to support passing `uiSchema` to the `validateFormData()` call so that it can be forwarded to `customValidate()` and `transformErrors()`
- In `@rjsf/utils`, updated the `ValidatorType` to take the `F` generic so that `validateFormData()` can be passed `uiSchema?: UiSchema<T, S, F>`
  - This required updating all of the schema-based functions to also take the `F` generic and properly adding generics to all the function calls
  - Also, the `CustomValidator` and `ErrorTransformer` types were updated to take all the generics needed to add the `uiSchema?: UiSchema<T, S, F>` parameter to the functions
- In `@rjsf/validator-ajv6`, updated the `customizeValidator` and `AJV6Validator` implementations to add the `S` and `F` generics
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/validator-ajv8`, updated the `customizeValidator` and `AJV8Validator` implementations to add the `F` generic
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/core`, updated the `ValidatorType`, `CustomValidator` and `ErrorTransformer` types to add the appropriate missing generics
  - Also passed `uiSchema` to the `validateFormData()` call
- Updated the `utility-functions.md` file to add the new generics
- Updated the `typescript.md` file to switch to using `customizeValidator()` with the generics to get the `validator`
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 8, 2023
Fixes rjsf-team#3170 by updating types and implementations to support passing `uiSchema` to the `validateFormData()` call so that it can be forwarded to `customValidate()` and `transformErrors()`
- In `@rjsf/utils`, updated the `ValidatorType` to take the `F` generic so that `validateFormData()` can be passed `uiSchema?: UiSchema<T, S, F>`
  - This required updating all of the schema-based functions to also take the `F` generic and properly adding generics to all the function calls
  - Also, the `CustomValidator` and `ErrorTransformer` types were updated to take all the generics needed to add the `uiSchema?: UiSchema<T, S, F>` parameter to the functions
- In `@rjsf/validator-ajv6`, updated the `customizeValidator` and `AJV6Validator` implementations to add the `S` and `F` generics
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/validator-ajv8`, updated the `customizeValidator` and `AJV8Validator` implementations to add the `F` generic
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/core`, updated the `ValidatorType`, `CustomValidator` and `ErrorTransformer` types to add the appropriate missing generics
  - Also passed `uiSchema` to the `validateFormData()` call
- Updated the `utility-functions.md` file to add the new generics
- Updated the `typescript.md` file to switch to using `customizeValidator()` with the generics to get the `validator`
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit that referenced this issue Jan 9, 2023
…call (#3358)

* fix: Fixed 3170 by passing `uiSchema` into the `validateFormData()` call
Fixes #3170 by updating types and implementations to support passing `uiSchema` to the `validateFormData()` call so that it can be forwarded to `customValidate()` and `transformErrors()`
- In `@rjsf/utils`, updated the `ValidatorType` to take the `F` generic so that `validateFormData()` can be passed `uiSchema?: UiSchema<T, S, F>`
  - This required updating all of the schema-based functions to also take the `F` generic and properly adding generics to all the function calls
  - Also, the `CustomValidator` and `ErrorTransformer` types were updated to take all the generics needed to add the `uiSchema?: UiSchema<T, S, F>` parameter to the functions
- In `@rjsf/validator-ajv6`, updated the `customizeValidator` and `AJV6Validator` implementations to add the `S` and `F` generics
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/validator-ajv8`, updated the `customizeValidator` and `AJV8Validator` implementations to add the `F` generic
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/core`, updated the `ValidatorType`, `CustomValidator` and `ErrorTransformer` types to add the appropriate missing generics
  - Also passed `uiSchema` to the `validateFormData()` call
- Updated the `utility-functions.md` file to add the new generics
- Updated the `typescript.md` file to switch to using `customizeValidator()` with the generics to get the `validator`
- Updated the `CHANGELOG.md` file accordingly

* - Add test cases to validate the proper passing of `uiSchema`
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
…mData()` call (rjsf-team#3358)

* fix: Fixed 3170 by passing `uiSchema` into the `validateFormData()` call
Fixes rjsf-team#3170 by updating types and implementations to support passing `uiSchema` to the `validateFormData()` call so that it can be forwarded to `customValidate()` and `transformErrors()`
- In `@rjsf/utils`, updated the `ValidatorType` to take the `F` generic so that `validateFormData()` can be passed `uiSchema?: UiSchema<T, S, F>`
  - This required updating all of the schema-based functions to also take the `F` generic and properly adding generics to all the function calls
  - Also, the `CustomValidator` and `ErrorTransformer` types were updated to take all the generics needed to add the `uiSchema?: UiSchema<T, S, F>` parameter to the functions
- In `@rjsf/validator-ajv6`, updated the `customizeValidator` and `AJV6Validator` implementations to add the `S` and `F` generics
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/validator-ajv8`, updated the `customizeValidator` and `AJV8Validator` implementations to add the `F` generic
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/core`, updated the `ValidatorType`, `CustomValidator` and `ErrorTransformer` types to add the appropriate missing generics
  - Also passed `uiSchema` to the `validateFormData()` call
- Updated the `utility-functions.md` file to add the new generics
- Updated the `typescript.md` file to switch to using `customizeValidator()` with the generics to get the `validator`
- Updated the `CHANGELOG.md` file accordingly

* - Add test cases to validate the proper passing of `uiSchema`
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
…mData()` call (rjsf-team#3358)

* fix: Fixed 3170 by passing `uiSchema` into the `validateFormData()` call
Fixes rjsf-team#3170 by updating types and implementations to support passing `uiSchema` to the `validateFormData()` call so that it can be forwarded to `customValidate()` and `transformErrors()`
- In `@rjsf/utils`, updated the `ValidatorType` to take the `F` generic so that `validateFormData()` can be passed `uiSchema?: UiSchema<T, S, F>`
  - This required updating all of the schema-based functions to also take the `F` generic and properly adding generics to all the function calls
  - Also, the `CustomValidator` and `ErrorTransformer` types were updated to take all the generics needed to add the `uiSchema?: UiSchema<T, S, F>` parameter to the functions
- In `@rjsf/validator-ajv6`, updated the `customizeValidator` and `AJV6Validator` implementations to add the `S` and `F` generics
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/validator-ajv8`, updated the `customizeValidator` and `AJV8Validator` implementations to add the `F` generic
  - Updated `validateFormData()` to accept a new optional `uiSchema` parameter that is passed to `transformErrors()` and `customValidate()`
- In `@rjsf/core`, updated the `ValidatorType`, `CustomValidator` and `ErrorTransformer` types to add the appropriate missing generics
  - Also passed `uiSchema` to the `validateFormData()` call
- Updated the `utility-functions.md` file to add the new generics
- Updated the `typescript.md` file to switch to using `customizeValidator()` with the generics to get the `validator`
- Updated the `CHANGELOG.md` file accordingly

* - Add test cases to validate the proper passing of `uiSchema`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants