issues1 Min Read

Jquery validate submitHandler not getting called

Gorav Singal

February 01, 2018

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

Share

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

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI video generation went from “cool demo” to “usable in production” in 2024-202…

AI Models in 2025 — Cost, Capabilities, and Which One to Use

AI Models in 2025 — Cost, Capabilities, and Which One to Use

Choosing the right AI model is one of the most impactful decisions you’ll make…

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

Generating one image with AI costs between $0.002 and $0.12. That might sound…

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

Two years ago, AI coding meant one thing: GitHub Copilot autocompleting your…

AI Agents Demystified — It's Just Automation With a Better Brain

AI Agents Demystified — It's Just Automation With a Better Brain

Let’s cut through the noise. If you read Twitter or LinkedIn, you’d think “AI…

Supply Chain Security — Protecting Your Software Pipeline

Supply Chain Security — Protecting Your Software Pipeline

In 2024, a single malicious contributor nearly compromised every Linux system on…