This topic is locked

Change the default confirmation before saving a record

2/8/2016 10:58:26 AM
PHPRunner General questions
P
pmorenoc07 author

Hi,
I'm trying to change this code with the sweetalert.
Has anyone done something similar to this?
http://xlinesoft.com/phprunner/docs/how_to_ask_for_confirmation_before_saving_record.htm



this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

if (confirm('Save record?')){

return true;

}else{

pageObj.delDisabledClass( pageObj.saveButton );

return false;

}

});


combined with this one



swal({

title: 'Save record?',

type: 'warning', showCancelButton: true,

confirmButtonColor: '#3085d6',

cancelButtonColor: '#d33',.

confirmButtonText: 'Yes',

closeOnConfirm: false },

function() {

swal(

'Saved!',

'Your record has been saved.',

'success'

);

});


Thank you all in advance for any help.

Sergey Kornilov admin 2/11/2016

Unfortunately this won't be easy. The problem is that built-in confirm() function is synchronous while all confirm replacements like 'sweetalert' are not. This means code execution won't stop when sweetalert is displayed and record will be saved anyway, no matter what user chooses.

P
pmorenoc07 author 2/12/2016



Unfortunately this won't be easy. The problem is that built-in confirm() function is synchronous while all confirm replacements like 'sweetalert' are not. This means code execution won't stop when sweetalert is displayed and record will be saved anyway, no matter what user chooses.


The problem I'm having is that sometime the browser add a check box: Prevent this page from creating additional dialogs.

How do I prevent this in my project without turn it off in browser settings?
Thank you.

Sergey Kornilov admin 2/12/2016

The best solution is to avoid using popups for this purpose. I don't know all details of your application but the use of popups of any kind is not the best practice. The better option is just to let user do what they doing with an option to rollback.

P
pmorenoc07 author 2/15/2016



The best solution is to avoid using popups for this purpose. I don't know all details of your application but the use of popups of any kind is not the best practice. The better option is just to let user do what they doing with an option to rollback.


Basically users log data every day, but they can go back and edit any of their entry, but we want to confirm any changes done before save it or even delete it.
What would be the best practice to build a rollback option?

Sergey Kornilov admin 2/15/2016

A couple of suggestions. All depends on your project details.

  1. Roll-back system. When record is modified save a previous copy of the record in archive table which should have the same structure plus a few service fields i.e. when this change was made, who made it etc. When you need to roll this record back copy it back from the archive table. Do not add a new record, just update the existing one.
  2. Another option is to display a "Confirm your changes" checkbox on the edit page and to make it required. This is way users have to check off this check box or record won't be saved. Similar to popup thing, just a better usability and no issues with the browser.