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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:54:42+00:00 2026-05-18T10:54:42+00:00

I am using the pub / sub jQuery plugin by Peter Higgins. I have

  • 0

I am using the pub / sub jQuery plugin by Peter Higgins. I have run into a problem with JavaScript validation.

This is the crux of the problem…

$.subscribe('/make', function(form_id, fields, path, type) { 
    for (var i=0; i < fields.length; i++) {
        $.publish('/validation/field', [ path+'check_field', $('*[name="'+fields[i]+'"]'), fields ]);
    }

    if ($('#'+form_id+' .error').length > 0) {
        alert('There are errors, please fix the errors before continuing.');
        return;
    }

The /validation/field will append errors to form fields. When you run this the first time the errors appear but everything is running so quickly an ajax request is sent to save the form. When the form is run the second time the function is stopped correctly as the error classes have been counted.

Is there a way around this?

  • 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-05-18T10:54:42+00:00Added an answer on May 18, 2026 at 10:54 am

    If the validation is asynchronous

    …the usual way you deal with this is to use a callback. In this case, you’d be looking for a callback defined by the validation that tells you when the validation has finished, at which point you could use your code for counting the resulting errors.

    If the validation is synchronous

    The above assumes that the validation involves an asynchronous activity of some kind. It doesn’t look like that pub/sub plugin provides any asynchronicity, so this would be down to what your subscriber for /validation/field does. If it does an ajax call or a setTimeout or similar, then you’ll need a callback.

    If the /validation/field subscriber does the validation synchronously, then I’m surprised you’re having a problem with the fields not being counted correctly afterward. But if you are, you can probably solve it by giving the browser just a moment to breathe:

    $.subscribe('/make', function(form_id, fields, path, type) { 
        for (var i=0; i < fields.length; i++) {
            $.publish('/validation/field', [ path+'check_field', $('*[name="'+fields[i]+'"]'), fields ]);
        }
    
        // Check results *after* giving the browser a moment to breathe:
        setTimeout(function() {
            if ($('#'+form_id+' .error').length > 0) {
                alert('There are errors, please fix the errors before continuing.');
                return;
            }
            // (...your code left off here, but I'm guessing the rest of the
            // function would also need to be within this new anonymous function...)
        }, 0);
    }
    

    The 0 parameter to setTimeout means “call me back in zero milliseconds”, but no browser will actually do that — it’ll typically be 4-10 milliseconds later. The point is that it will be asynchronous, after the browser has had a chance to catch up and re-invoke the JavaScript layer.

    Be careful though, make sure that the thing doing the validating is doing it synchronously. If it isn’t, if it’s doing anything async, then the above introduces a race condition into your code where sometimes it will seem to work, other times it won’t work. Race conditions will bite you, so double-check. 🙂

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

Sidebar

Related Questions

I'm writing a jQuery plugin and using .on and .trigger as my pub/sub system.
I am using Addy Osmani's pub sub method: var topics = {}; jQuery.Topic =
We have a wcf pub/sub setup using reliable sessions via netTcpBinding and on one
We have been using PollingDuplexHttpBinding for some time to do Pub/Sub messaging. We have
I have a simple pub-sub setup on a mid-sized network, using ZMQ 2.1. Although
Looking for advice/pro's/con's on using the memory cache servers for pub/sub esp wrt a
I need to call a stored procedure using JPA and found this article: http://www.oracle.com/technology/pub/articles/vasiliev-jpql.html
I am trying to set up pub-sub between 1 publisher and multiple subscribers using
We are using a pub-sub model in our WCF application that pretty much follows
I've been looking at using Redis Pub/Sub as a replacement to RabbitMQ. From my

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.