This is a migrated thread and some comments may be shown as answers.

Using promise-based confirmations in save() after incell edit, allowing to change the value

3 Answers 585 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lance
Top achievements
Rank 1
Lance asked on 24 May 2016, 05:22 PM

We need to run some user confirmations for certain changes that occur with our incell-edited table. Our standard confirmation dialog is an async dialog, not Window.confirm(), which seems to cause some problems.

If we were just using the synchronous confirm(), then we could easily preventDefault() upon rejection, but the async confirm comes too late for that.

Additionally, there are times that we want to modify the value that the user enters as part of the save() call, but I haven't figured out how to get that to work.

In this fiddle (http://jsfiddle.net/LMFinney/3qkpLjvt/2/), I've simulated the async confirm dialog by wrapping confirm() in a Promise.resolve(). And I've simulated changing the value of the user-entered data by doubling odd entries. In this case, preventDefault() doesn't work because it's too late, and setting the modified value actually clears the value instead.

Is there another approach for these two issues?

3 Answers, 1 is accepted

Sort by
0
Stephen
Top achievements
Rank 2
answered on 24 May 2016, 06:03 PM

The problem is that the caller of save() (the grid code) is not waiting for the promise to resolve before it continues on and commits the change as it has no idea your save handler is a promise.

I don't really have a solution other than I would try to preventDefault() immediately and then in confirm handler, update the model and in the else case do nothing.

 

As for not being able to modify the value:

1. The syntax for set() is model.set('FieldName', newValue) NOT model.set('FieldName') = newValue.

2. Also, the new value is in the e.values property and has not yet been written to the model.  If you allow the save to commit, e.values.YourField will get written to e.model.YourField by the framework.

When you do e.model.set('KeyCode', value) the caller of save() will most likely overwrite it with the value in e.values.

You may have to try setting e.values.KeyCode = newValue instead.

0
Lance
Top achievements
Rank 1
answered on 24 May 2016, 06:09 PM

On the promise issue - I agree that the timing of the promise result is the cause of the problem.I'll try your suggestion.

On modifying - thanks for catching my mistake. That was really silly. I've updated it here: http://jsfiddle.net/LMFinney/3qkpLjvt/3/

This works with set(). Using e.values.KeyCode = newValue didn't work.

0
Lance
Top achievements
Rank 1
answered on 24 May 2016, 06:10 PM

I've updated further: http://jsfiddle.net/LMFinney/3qkpLjvt/4/

It seems to work.

Thanks

Tags
Grid
Asked by
Lance
Top achievements
Rank 1
Answers by
Stephen
Top achievements
Rank 2
Lance
Top achievements
Rank 1
Share this question
or