tnc-ba / strongTNC

BYOD TNC Database Management Tool
GNU Affero General Public License v3.0
0 stars 0 forks source link

Error handling for validation calls #287

Open dbrgn opened 10 years ago

dbrgn commented 10 years ago

Validation does AJAX requests to check-URLs.

Is it possible to easily add an error-alert if the request fails, @d22?

A possible case where this is needed is if CSRF validation fails (e.g. because the user enabled secure cookies but doesn't use TLS).

d22 commented 10 years ago

Yes, this is possible, the remote validation uses the jQuery ajax object, so this is possible (example from packages.js):

...
remote: {
    url: "/packages/check",
    type: "post",
    error: function () {
        alert('Remote validation failed');
    },
    data: {
        'package': function () {
            return $('#packageId').val()
        },
        'name': function () {
            return $("#name").val()
        },
        csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]', '#packageform').
    }
}
...