onPreSubmit is not preventing Submit

onPreSubmit is not preventing Submit

bpanbpan Posts: 1Questions: 1Answers: 0

We're upgrading from 1.9 and running into an issue. We're upgrading to DT 1.10.2, with Editor 1.3.3, and jQuery 1.11.1. Our onPreSubmit no longer seems to prevent a trip to the server when a validation error has occurred. I stepped through this code in Chrome and we are indeed returning false, but the AJAX call still happens.

Here's our configuration:

  onPreSubmit: function (o) {
    var errorFound = false;
    if (o.data.FIRST_NAME.trim() == '') {
      editor.error('FIRST_NAME', "First Name required");
      errorFound = true;
    }
    if (o.data.LAST_NAME.trim() == '') {
      editor.error('LAST_NAME', "Last Name required");
      errorFound = true;
    }
    if (o.data.EMAIL.trim() == '') {
      editor.error('EMAIL', "Email required");
      errorFound = true;
    }
    if (errorFound) {
      editor.error("Invalid input");
      return false;
    }
    return true;
  },

The docs say that the 1.9 onPreSubmit should behave the same. Are we missing something?

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    There is an example of using preSubmit here, which demonstrates the behaviour you are looking for (i.e. not hitting the server).

    Worth noting that onPreSubmit and preSubmit are the same - the latter is the documented style in Editor 1.3 to match DataTables and the other extensions, but the on prefix style will still work.

    Can you link to a test case showing the issue, as there is something going wrong somewhere, but I will need to be able to reproduce the issue to figure out what is going wrong.

    Thanks,
    Allan

This discussion has been closed.