CarlosNZ / json-edit-react

React component for editing/viewing JSON/object data
https://carlosnz.github.io/json-edit-react/
MIT License
187 stars 18 forks source link

How to add a confirmation popup before deleting a record #100

Closed rahulcs1988ai closed 4 months ago

rahulcs1988ai commented 4 months ago

is there any method to override the onDelete functionality so that I can show a confirmation popup before deleting a record

CarlosNZ commented 4 months ago

Yes, you just pass in your function as the onDelete prop. Your function should return false or an error string if it shouldn't do the delete action, and nothing if it should proceed as normal. Something like:

onDelete={
  ( {name} ) => {
     const result = confirm(`Are you sure you want to delete ${name}?`)
     if (result === false) return false  // The data won't be updated
     else return  // The data will be updated
  }
}

See Update functions for more detail.

Hope that helps.

rahulcs1988ai commented 4 months ago

@CarlosNZ Thank you so much :)