issues|February 01, 2018|1 min read

Jquery validate submitHandler not getting called

TL;DR

The submitHandler callback in jQuery validation may not fire if the validate method is called incorrectly or the form element selector is wrong; ensure proper configuration of the validate plugin.

Jquery validate submitHandler not getting called

Introduction

I'm using jquery to validate my form submitted, and I've also defined a submitHandler function on submit of form. But, the issue is that submitHandler is not being called.

Code that I have is:

handleSubmit() {
        this.ui.form.validate({
            debug: false,
            highlight: function (element) {
                $(element).closest('.form-group').addClass('has-error');
            },
            unhighlight: function (element) {
                $(element).closest('.form-group').removeClass('has-error');
            },
            errorElement: 'span',
            errorClass: 'help-block',
            errorPlacement: function (error, element) {
                if (element.parent('.assertion-group').length) {
                    error.insertAfter(element.parent());
                } else {
                    error.insertAfter(element);
                }
            },
            submitHandler: function () {
                   //my code to submit
            }.bind(this)
        });
    },

Solution

I was exhausted in searching for the issue, and debugging. After closely examining the html form, I checked html of my button.

It was:

  
<button class="btn btn-success" id="buttonAction" type="button">Submit</button>

I changed it to:

  
<button class="btn btn-success" id="buttonAction" type="submit">Submit</button>

So, I needed to change button type from the button to submit. And, the problem resolved. Huh

Related Posts

Python SMTP Email Code - Sender Address Rejected - Not Owned By User

Python SMTP Email Code - Sender Address Rejected - Not Owned By User

Introduction In a normal email sending code from python, I’m getting following…

Explaining issue&#58; response to preflight request doesn't pass access control check

Explaining issue&#58; response to preflight request doesn't pass access control check

You are developing a nodejs web application having some UI and backend APIs…

How to Fix Drupal Mysql error - Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes

How to Fix Drupal Mysql error - Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes

Introduction While this topic may applicable to all mysql/mariadb users who…

Solving Jboss Wildfly Oracle JDBC driver problem, with Dockerfile

Solving Jboss Wildfly Oracle JDBC driver problem, with Dockerfile

Assuming your web application is using oracle, and you are deploying your app on…

React JS router not working on Nginx docker container

React JS router not working on Nginx docker container

Problem Statement I developed a simple ReactJS application where I have used…

Mac showing strange incorrect month name

Mac showing strange incorrect month name

Introduction to problem So, on my mac, I’ev set timezone to my local city i.e…

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…