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

4 posts, 0 answers
  1. Lance
    Lance avatar
    6 posts
    Member since:
    Jan 2016

    Posted 24 May 2016 Link to this post

    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?

  2. Stephen
    Stephen avatar
    90 posts
    Member since:
    Jan 2011

    Posted 24 May 2016 in reply to Lance Link to this post

    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.

  3. Lance
    Lance avatar
    6 posts
    Member since:
    Jan 2016

    Posted 24 May 2016 in reply to Stephen Link to this post

    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.

  4. Lance
    Lance avatar
    6 posts
    Member since:
    Jan 2016

    Posted 24 May 2016 in reply to Stephen Link to this post

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

    It seems to work.

    Thanks

Back to Top