delete validation on preSubmit

delete validation on preSubmit

neustarneustar Posts: 9Questions: 3Answers: 0

validating create and edit is great using preSubmit, but delete has no DATA other than ID available, so what method do people use to validate prior to delete? I do not want to allow deleting an active customer, for example.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,714Questions: 1Answers: 10,103 Site admin
    Answer ✓

    Good question! Would you could do is use the modifier() method to get the row being edited and then access its data using the DataTables API (row().data()).

    For example:

    if ( action === 'remove' ) {
      var data = table.row( editor.modifier() ).data();
      ... validate with data
    }
    

    Regards,
    Allan

  • neustarneustar Posts: 9Questions: 3Answers: 0

    That works, thx. As an aside I have to say I think it would be simpler all around to pass the full DATA on all create,edit,delete events rather than trying to economize delete by allowing it to access ID only. It would seem to be more consistent, one less thing to treat special. Just a comment though. Thx for the tip

  • allanallan Posts: 61,714Questions: 1Answers: 10,103 Site admin

    The thing is that preSubmit provides access to the data that is being sent to the server (so it can be checked or modified), but on delete no data is being sent since it isn't at all needed, hence why it isn't available.

    However, this should be a bit easier I see! Perhaps the data should be passed in as an extra attribute, one representing the current data, not the new values. I'll look into that - thanks for the suggestion!

    Allan

This discussion has been closed.