Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7873229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:27:01+00:00 2026-06-03T02:27:01+00:00

I have a form that is using the jQuery validate functionality, with some custom

  • 0

I have a form that is using the jQuery validate functionality, with some custom functions validating the values with ajax posts.

My problem is when I submit the form, I have the submitHandler do ajax post to check if the field is valid by checking in the DB. I only want the form to submit if the value returned is valid.

(function ( $ ) {
    $.fn.checkValidSubDomain = function (params) {
        params['siteID'] = wlSiteID;
        var deferred = $.Deferred();
        var promise = deferred.promise();

        $("div#"+$(this).attr('id')+"Info").html(copyItems["info_checkingStatus"]);
        var jqxhr = $(this).ajaxPost('checkValidSubDomain', params)
        jqxhr.success(function (data){
            if (data.validSubdomain) {
                $("div#"+$(this).attr('id')+"Info").html(copyItems["info_"+$(this).attr('id')+"Available"]);
                deferred.resolve(data);
            } else {
                $("div#"+$(this).attr('id')+"Info").html(copyItems["err_"+$(this).attr('id')+"Unavailable"]);
                deferred.reject(jqxhr, 'error');
            }
        })
        jqxhr.error(function (jqXHR, status, error){
            $("div#"+$(this).attr('id')+"Info").html(copyItems["err_"+$(this).attr('id')+"Unavailable"]);
            deferred.reject(jqXHR, status, error);
        });
        return promise;
    };
})(jQuery);

var validationRules = {
    submitHandler: function(form) {
        var promise;
        if ($('input[name="domainSetting"]:checked').val() == 'subDomain') {
            alert("checking subdomain - " + $('#subDomainSiteName').val())
            promise = $('#subDomainSiteName').checkValidSubDomain({'subDomain': $('#subDomainSiteName').val(), 'domain':$("#domainSelect option:selected").val()});
        } 
        promise.done(function() {
            form.submit();
        });
        return false;
    },
    onfocusout: false,
    onkeyup: false,
    rules: {
        subDomainSiteName: {
            required: {
                depends: '#domainSettingSubDomain:checked'
            }
        }
    }
};
$('#domainSettingsFRM').formValidation(validationRules);

I’m not sure how I get to the form to only submit if the field is valid. Currently, it’s just showing the alert and then submitting the form regardless of the value.

Any help appreciated

EDIT

I think I just figured it out. Once the async ajax call is finished, the promise.done() will trigger. At that point I simply check the state to see if it is resolved or rejected. Changing the code to the following seems to do the trick.

promise.done(function() {
    if (promise.state() == "resolved") {
        form.submit();
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:27:02+00:00Added an answer on June 3, 2026 at 2:27 am

    without seeing a demo page with that code, at a first look that behaviour could be due to a javascript error: where you wrote

     promise.done()(function() {
                form.submit();
     }, null);
    

    you should write instead

     promise.done(function() {
         form.submit();
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that I am using AJAX to pass values with. The
I have a form that is using jQuery Validate plugin for client side validation,
I have a question form that I want to validate using jquery. My form
I have a form and I'm using jQuery to validate that the have entered
I have to build a registration form using asp.net mvc 3 jquery validate. That
I have started using jQuery and rails. I have made a simple form that
I have a form on a webpage that I submit using the jquery form
I want to submit a form that have many checkboxes with different values, using
I have a form that validates using jquery. The form's id is contact and
I'm using the jQuery form wizard plugin. I have 20 questions that each have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.