Quantcast
Channel: Editor — DataTables forums
Viewing all articles
Browse latest Browse all 3801

confirm PIN preRemove

$
0
0

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


Viewing all articles
Browse latest Browse all 3801

Trending Articles