Django jquery ajax remote validate returns TypeError: Cannot read property 'apply' of undefined -
i trying validate 1 field of form using jquery & validate.js in django.
i've read many posts, regardless of various examples, fails on same error.
simply use remote method included in plugin. last 1 hit , simplest code sample, same result:
jquery.validate.js:1594 uncaught typeerror: cannot read property 'apply' of undefined. exception occurred when checking element id_client_code, check 'remote' method. @ function.$.ajax (jquery.validate.js:1594) @ $.validator.remote (jquery.validate.js:1529) @ $.validator.check (jquery.validate.js:777) @ $.validator.element (jquery.validate.js:492) @ $.validator.onfocusout (jquery.validate.js:300) @ htmlinputelement.delegate (jquery.validate.js:423) @ htmlformelement.dispatch (jquery-3.2.1.slim.min.js:3) @ htmlformelement.q.handle (jquery-3.2.1.slim.min.js:3) @ object.trigger (jquery-3.2.1.slim.min.js:3) @ object.simulate (jquery-3.2.1.slim.min.js:3)
here views.py section remote, returns false expected when called in tab:
def validate_client_code(request): is_available = 'false' if request.is_ajax(): client_code = request.get.get('client_code', none) try: client.objects.get(client_code) except client.doesnotexist: is_available = 'true' return httpresponse(is_available)
and here script block
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script> <script> $("#new-client").validate({ rules: { client_code: { required: true, remote: "/clients/ajax/validate_client_code/" }, messages: { client_code: {remote: "the client code taken"} } } }); </script>
html rendered (using crispy forms):
<form class="form-horizontal" method="post" action="/clients/new/" enctype="multipart/form-data" id="new-client"> <input type='hidden' name='csrfmiddlewaretoken' value='ek...'/> <div id="div_id_client_code" class="form-group"><label for="id_client_code" class="form-control-label requiredfield"> client code<span class="asteriskfield">*</span></label> <div class=""><input type="text" name="client_code" maxlength="10" class="textinput textinput form-control" required id="id_client_code"/> </div> </div> <div id="div_id_client_name" class="form-group"> <div class="control-group"> <div class="controls"> <button class="btn btn-primary">update</button> <a class="btn btn-secondary" href="/clients/" role="button">cancel</a> </div> </div></form>
chrome console keeps spitting out error above when enter value (known dupe or not).
Comments
Post a Comment