victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 476 forks source link

Problem with validation callbacks: onSuccess, onError #649

Closed ivelios2 closed 6 years ago

ivelios2 commented 6 years ago

Hi, I have problem with info alerts callbacks.

My code:

<form method="post" accept-charset="utf-8" class="my-form" role="form" id="my-form">
...
 <button class="submit btn btn-lg btn-block" type="submit"><b style="font-size:16px; text-transform:uppercase;">Submit</b></button>

<script>
 $(function() {
    // setup validate
    $.validate();
  });
</script>
 <script>
 $.validate({
   modules : 'logic'
 });
 $.validate({
   lang : 'pl'
 });
 $.validate({
   form : '#my-form',
   onSuccess : function() {
     alert('Valid!');
     return false; // prevent ordinary form submission
   },
   onError : function() {
     alert('no valid!');
   },
 });
 </script>

With this code, I don`t see any alerts.

Alerts I would like to use:

https://www.w3schools.com/bootstrap/bootstrap_alerts.asp

Pls help :[

victorjonsson commented 6 years ago

Why do you have multiple calls to $.validate? Try this instead:

<sccript>
 $.validate({
   form : '#my-form',
   lang: 'pl',
   modules: 'logic',
   onSuccess : function() {
     alert('Valid!');
     return false; // prevent ordinary form submission
   },
   onError : function() {
     alert('no valid!');
   },
 });
</script>

Let me know if your problems persists.

ivelios2 commented 6 years ago

THX A LOT! Working great.

This script is great!