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

Any way to pass a callback to beforeSaveCell function? #1245

Closed
CoralSilver opened this issue Apr 21, 2017 · 12 comments
Closed

Any way to pass a callback to beforeSaveCell function? #1245

CoralSilver opened this issue Apr 21, 2017 · 12 comments

Comments

@CoralSilver
Copy link

I want to implement a confirmation modal and block the beforeSaveCell function until the user has hit OK or Cancel button. Is there a way to do this?

@AllenFang
Copy link
Owner

Use options.handleConfirmDeleteRow

const options = {
  handleConfirmDeleteRow: function(cb, dropRowKeys) {
    //.... ask user here
    if (ok) cb();
    else .....
  }
}

@CoralSilver
Copy link
Author

Do you mean I should use handleConfirmDeleteRow instead of beforeSaveCell for cell editing? Do I need to include a function in this.cellEditProp?

@AllenFang
Copy link
Owner

ah.... shit, my bad. please ignore it, sorry.

For beforeSaveCell, we dont have this kind of feature but I think maybe I can support it like options.handleConfirmDeleteRow

@CoralSilver
Copy link
Author

Just to be clear I'm trying to implement a custom confirm modal not the browser confirm.

@CoralSilver
Copy link
Author

That would be great. So you can't pass a can't pass a callback into validator then either right?

@AllenFang
Copy link
Owner

um~
my solution is just like options.handleConfirmDeleteRow

const options = {
  beforeSaveCell: function(rowIndex, fieldName, value, cb) {
    //open your model and pass cb to your application
   return "SOME_SPECIFIED_VALUE";
  }
}

// if user confirm this editing, call the `cb`

is that ok for you?

@CoralSilver
Copy link
Author

The function doesn't seem to be firing. Do I have to specify prop for cellEditProp beforeSaveCell still?

@AllenFang
Copy link
Owner

AllenFang commented Apr 26, 2017

The function doesn't seem to be firing

of course, because I doesn't implement it yet, I just want to confirm with you

@CoralSilver
Copy link
Author

CoralSilver commented Apr 26, 2017

Oh sorry. I didn't understand. I'm trying to call the confirm modal using the React Confirm plugin which returns a promise. With your proposed solution can I do something like this?:

const options = {
beforeSaveCell: function(rowIndex, fieldName, value, confirmEdit) {
        let toSave = false;
        confirm('Are you sure you want to edit this value?').then(
        (result) => {
          // `proceed` callback
          console.log('proceed called');
          toSave = true;
        },
        (result) => {
          // `cancel` callback
          console.log('cancel called');
          toSave = false;
        }
        );
       // save change to database if toSave is true and update cell, otherwise return false and have cell reset or should this replace proceed callback line?
        this.confirmEdit(rowIndex, fieldName, value, toSave);
}

@AllenFang
Copy link
Owner

@CoralSilver, got it, I'll try it, if it work, I'll release in near future. Anyway, I guess it can work well :)

AllenFang added a commit that referenced this issue May 6, 2017
@AllenFang
Copy link
Owner

Fixed on v3.3.1, and check https://github.com/AllenFang/react-bootstrap-table/blob/master/examples/js/cell-edit/cell-edit-hook-table.js#L42 to learn how to use it.

let me know if you still got any questions, thanks.

@CoralSilver
Copy link
Author

@AllenFang Thanks so much for making that change. It works perfectly with React-Confirm.

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