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

rowEditValidator validates the original data rather than the new one #2618

Closed
rburgst opened this issue Jan 30, 2022 · 1 comment
Closed
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@rburgst
Copy link
Contributor

rburgst commented Jan 30, 2022

I'm submitting a ... (check one with "x")

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57

Codesandbox Case (Bug Reports)
Please fork the codesandbox below and create a case demonstrating your bug report. Issues without a codesandbox have much less possibility to be reviewed.

https://codesandbox.io/s/primereact-datatable-validation-error-fblng

Current behavior
When providing a rowEditValidator it is being called with the original (unedited) data, rather than the updated data.

Expected behavior
rowEditValidator should be called with the edited data rather than the original one.

Minimal reproduction of the problem with instructions

  1. open the sandbox https://codesandbox.io/s/primereact-datatable-validation-error-fblng
  2. click on the edit icon in the first row
  3. change "Bamboo watch" to "2Bamboo watch"
  4. click save
  5. watch the console output, it says
    validator 
    {id: "1000", code: "f230fh0g3", name: "Bamboo Watch", description: "Product Description", image: "bamboo-watch.jpg"…}
    

Please tell us about your environment:
Mac OSX

  • React version:
    17.0.2

  • PrimeReact version:
    7.0.0 and 7.2.0

  • Browser: I guess its all of them

  • Language: TypeScript (probably does not matter either)

@rburgst
Copy link
Contributor Author

rburgst commented Jan 30, 2022

The problem is most likely here

https://github.com/primefaces/primereact/blob/master/components/lib/datatable/BodyRow.js#L276-L278

In BodyCell
https://github.com/primefaces/primereact/blob/master/components/lib/datatable/BodyCell.js#L434
the event also contains the variable newData

However in BodyRow it uses the old stored data to validate.

I guess the following would fix this

        const valid = this.props.rowEditValidator ? this.props.rowEditValidator(e.newData, { props: this.props.tableProps }) : true;

rburgst pushed a commit to rburgst/primereact that referenced this issue Jan 30, 2022
- when validating with rowEditValidator we need to use the
  updated data for validation
@yigitfindikli yigitfindikli added the Type: Bug Issue contains a defect related to a specific component. label Mar 28, 2022
@yigitfindikli yigitfindikli added this to the 8.0.0 milestone Mar 28, 2022
@mertsincan mertsincan modified the milestones: 8.0.0, 8.0.0-rc.1 Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

No branches or pull requests

4 participants