Delete-button with confirmation in inline form commands

Delete-button with confirmation in inline form commands

hasenumberonehasenumberone Posts: 14Questions: 1Answers: 0
edited March 2013 in Editor
In the example for inline form commands the records will be deleted without confirmation. How can i change that?

[code]// Delete a record (without asking a user for confirmation)
$('#example').on('click', 'a.editor_remove', function (e) {
e.preventDefault();

editor.remove( $(this).parents('tr')[0], '123', false, false );
editor.submit();
} );[/code]

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    From the documentation ( http://editor.datatables.net/docs/current/Editor.html#remove ):

    [code]
    // Delete a given row with a message to let the user know exactly what is
    // happening
    editor.message( "Are you sure you want to remove this row?" );
    editor.remove( row_to_delete, 'Delete row', {
      "label": "Confirm",
      "fn": function () { this.submit(); }
    } );
    [/code]

    Note that the difference is the code in the live example will automatically call `submit` while the example in the documentation uses a callback for it, which is triggered in the button.

    Allan
  • hasenumberonehasenumberone Posts: 14Questions: 1Answers: 0
    So, how do i have to implement it with inline button?
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    edited March 2013
    Put the code that I pasted into your click handler, instead of the one you don't want?

    [code]
    $('#example').on('click', 'a.editor_remove', function (e) {
    e.preventDefault();

    editor.message( "Are you sure you want to remove this row?" );
    editor.remove( $(this).parents('tr')[0], 'Delete row', {
    "label": "Confirm",
    "fn": function () { this.submit(); }
    } );
    } );
    [/code]

    Allan
  • hasenumberonehasenumberone Posts: 14Questions: 1Answers: 0
    [code]
    // Delete a record (without asking a user for confirmation)
    $("#adminix_gallery_fotos").on("click", "a.editor_remove", function (e) {
    e.preventDefault();
    editor.message( "Are you sure you want to remove this row?" );
    editor.remove( $(this).parents("tr")[0], "Delete row", {
    "label": "Confirm",
    "fn": function () { this.submit(); }
    } );
    } );
    [/code]

    This works.
  • hasenumberonehasenumberone Posts: 14Questions: 1Answers: 0
    oh, double posting. Thank you! ;-)
This discussion has been closed.