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 8238319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:46:23+00:00 2026-06-07T19:46:23+00:00

I have a form where users are entering account numbers and I need to

  • 0

I have a form where users are entering account numbers and I need to check that the entered account numbers are unique when the save button is clicked, but before form submission. This is on the magento backend and the ajax call is pointing to the function acctnumAction() in the indexController.

The number of account numbers is dynamic, there could be up to 5, but as few as 1, so I need to do an each loop on the items. I gave the account number fields their own class and loop over that.

This is what I’ve got.

    function acctCheck(){
        jQ.each(jQ(".acctnum"), function(x, y){
            var acct = jQ(this).val();
            var field = this;
            jQ.get("'.Mage::helper('core/url')->getHomeUrl().'dealerlocator/index/acctnum", {acctnum: acct}, function(data){
                var items = JSON.parse(data);
                if(items != ""){
                    $(field).addClass("validation-failed");
                    return false;
                }
            });
        });
    }
    function saveAndContinueEdit(){
        if(acctCheck() !== false){ editForm.submit(); }
    }

The save button onclick hits saveAndContinueEdit() and runs the function to check the account numbers.

I know this won’t work, the ajax will run asynchronously and return nothing before it could return false, and as long as it isn’t false, it submits. But I have tried wrapping the ajax call in $.when to no avail, i wrapped the if in saveAndContinueEdit() in a $.when, like so

    function saveAndContinueEdit(){
        jQ("#continueEdit").val("1");
        jQ.when(acctCheck()).done(function(valid){
            if(valid !== false){
                editForm.submit();
            }
        });
    }

but that didnt do the trick either, and is probably not even how it’s supposed to work, I was just trying whatever I could come up with.

The point of having it in the each is so that I could set a variable to false if an account number isnt valid, but still iterate through the rest so that the class will still be added to the fields if they are invalid, so the user will know, instead of fixing one then another pops up as invalid, even though my examples aren’t coded that way. I know the data that is returned by the get is valid, it just won’t run synchronously.

Anyone have any ideas?

  • 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-07T19:46:26+00:00Added an answer on June 7, 2026 at 7:46 pm

    I got it working using deferreds.

        function eachAcctChk(elem){
            return jQ.get("'.Mage::helper('core/url')->getHomeUrl().'dealerlocator/index/acctnum", {account: jQ(elem).val(), dealer: '.$data["id"].'}, function(data){
                if(data != "none"){
                    jQ(elem).addClass("validation-failed");
                    valid = false;
                }
            });
        }
        function saveAndChk(){
            jQ("#continueEdit").val("0");
            AcctChk();
        }
        function saveAndContinueChk(){
            jQ("#continueEdit").val("1");
            AcctChk();
        }
        function AcctChk(){
            var deferreds = [];
            jQ(".acctnum").each(function(){
                deferreds.push(eachAcctChk(this));
            });
            jQ.when.apply(null, deferreds).then(function(){
                if(valid){
                    editForm.submit();
                } else {
                    valid = true;
                    alert("The highlighted dealer account numbers are already in use by another company. Unique account numbers are required.");
                }
            });
        }
    

    Returning the entire ajax (get) call acts as a deferred, i throw them all in an array and pass that to when(). So when all of the ajax calls complete, it hits then(), and voila.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Overview: My application has an enrollment form. Users have a habit of entering
On my site, I have a form that users fill out to become a
I have a dynamic form that users can add/delete sets of input fields. I
I have a data entry form in a HTML5 application that users will be
I have a form on a website that needs validating before entering the form
I have a form where users are entering 35 different fields. I have a
I have a form that asks users to enter a start and end time
I have a form with one textbox and one button. Here I need to
I have a form with one textbox and one button. Here I need to
I have a drupal form where users are entering a list of names (via

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.