confirm PIN preRemove
confirm PIN preRemove
Hi,
My goal here is to confirm row delete with a user PIN number.
I used formMessage
to add password input in the delete confirmation modal
I tried different approaches that have issues,
approach 1: extending the button
formButtons: [
{
label: 'Delete',
fn: function() {
var pin = $('#PIN').val();
$.ajax({
url: 'api/verify_pin',
type: 'POST',
data: {
pin: pin
}
})
.done(function(data) {
// assuming PIN match, I cannot trigger row delete here
//editor.remove( this );
//this.remove( this.modifier() )
})
.fail(function() {
});
}
},
}
]
so problem in 1 is that I failed to trigger the delete
approach 2: I thought of server side validation, by sending the PIN with data then validate in
->on( 'preRemove', function ( $editor, $id, $values ) {
})
However,
editor.on('preSubmit', function( e, data, action ) {
// require pin before delete
if(action=='remove'){
var pin = $('#PIN').val();
editor.add({name:'delete_pin', def:pin});
// I cannot send the PIN as new field using editor.add()
}
});
And my problem in 2 is that I failed to send the PIN as new field
This question has an accepted answers - jump to answer
Answers
Use
initSubmit
to add the new form field. Doing it inpreSubmit
is too late. The data to be sent to the server has already been queued and readied by that point.Allan
for
action=="remove"
it doesn't seem to allow adding new fields. could be because the fields are not showing in the delete modal form.Anyway, using
initSubmit
Promise
example, I was able to solved my problem by adding my logic there. possible that usingPromise
with any cancellable event would work for my case.thanks heaps Allan.