Issue with inError()

Issue with inError()

mguinnessmguinness Posts: 85Questions: 12Answers: 1

There appears to be an issue with inError() not correctly reflecting the error state in preSubmit.

Using the test case below, the console output should be false, false, '' on the first submit, then true, true, 'Dummy Error'on the second submit.

https://live.datatables.net/judugaza/1/edit?js,console,output

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Actually this is intentional. It might seem slightly counter intuitive at first, but what is happening is that when the form is submitted, we assume know knowledge of the validity of the form's content. It is up to preSubmit (or others) to determine if the contents are currently valid.

    This is a comment in the submit API method's code:

        // Remove the global error (don't know if the form is still in an error
        // state!)
        this.error();
    

    The same applies to the fields.

    If that wasn't automatically done in Editor, then you as a developer would be required to clear out any errors that might have been set already, and they could have come from a number of places. We could make a method to allow them to be cleared out, but I took the decision to automatically clear them, under the assumption that the form would be validated on each submit (which it should be anyway).

    Allan

  • mguinnessmguinness Posts: 85Questions: 12Answers: 1

    Thanks for the explanation Allan, this behaviour must have have changed after 1.7 since I've just upgraded. Not an issue, but would you be able to update the documentaion in inError() to reflect this?

    As an aside I also noted that in the source you have $(this.dom.formError); which appears to be superfluous.

    function inError(inNames) {
        $(this.dom.formError);
        // Is there a global error?
        if (this.s.globalError) {
            return true;
        }
        ...
    }
    
  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Thanks - I spotted that as well while looking into this. I've committed a change to the inError() docs and that will update on the site soon.

    Allan

Sign In or Register to comment.