Jquery Validation remote method always shows invalid

I am trying to validate an html function with django and jQuery validation. I want jQuery validation to check if the inserted email already exists,

This is my jQuery valdiation remote

           email: {
            validators: {
              notEmpty: {
                message: 'email field can not be empty'
              emailAddress: {
                message: 'is not a valid email'
              remote: {
                message: 'email is already in use',
                url: '/validate_email/',
                type: 'post',
                data: {
                  email: function() {
                    return $('#email').val();

The url calls to my view def which is

def validate_email(request):
    email = request.GET.get('email', None)
    data = not Vendors.objects.filter(email__iexact=email).exists()
    if data is True:
        data = "true"
        data = "false"

    return JsonResponse(data, safe=False)

I am getting a correct "true" or "false" JsonResponse, but the message always shows that the email is already in use and keep asking me to correct it.

I tried passing the JsonResponse as true or false without "", also tried passing the JsonResponse as is_taken: true or is_taken: false.

In your Django view, you need to return a JSON response in the following format:

return JsonResponse({"valid": data})

The jQuery Validation plugin will understand that the email is valid if the response is "valid":true and invalid if the response is "valid": false.

Back to Top