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

  • Home
  • SEARCH
  • 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 8623007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:11:01+00:00 2026-06-12T07:11:01+00:00

I implemented some custom validation logic with JQuery and Unobtrusive validation with help of

  • 0

I implemented some custom validation logic with JQuery and Unobtrusive validation with help of the following post:

Manually set unobtrusive validation error on a textbox

To save you time reading through that post here is the simple javascript that forces a validation message to be displayed if something fails:

On my textbox .blur():

var errorArray = {};
errorArray["Slug"] = 'Some error message for the Slug text box';
$('#SomeFormId').validate().showErrors(errorArray);

Works great.

My problem is while the failed validation message is displayed, when submit is clicked the form submits just fine.

How can I implement custom validation with code above and prevent the form from being submitted when the message is displayed ? I tired doing something like $('#SomeFormId').valid = false; but it didn’t work.

Thank you.

  • 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-12T07:11:02+00:00Added an answer on June 12, 2026 at 7:11 am

    Using $('#SomeFormId') will not work because when you do:

    $('#SomeFormId').valid = false;
    

    and then when you access it in your form submit handler again using (what I assume):

    var form = $('#SomeFormId');   // or $(this)
    if (form.valid) {
        //
    }
    

    You’re essentially creating two different objects, even though they’re referring to the same DOM element. So setting valid = true in one will not update it in the second.

    The code you gave is very barebones though, so I’m assuming that your validation is separate from your submit handler (since it’s in blur anyway), so what you can do is utilize something like .data() or a flag (just make sure that it’s in context).

    // on blur
    $('#SomeFormId').data('isvalid', false);    // invalid
    
    // on submit
    var isvalid = $('#SomeFormId').data('isvalid');
    if (!isvalid) {
        // invalid form
        ev.preventDefault();
    }
    

    EDIT

    The jQuery Event object

    When you bind a function as an event handler in jQuery, one of the things that jQuery does silently for you is it “creates” a normalized Event object for you. This will contain information about the event you can use in the handler, and also allows you to control the behavior of the event in some ways.

    // setting a submit event on my form
    //                                       |   whatever you put here 
    //                                       V   is the event object.
    $('#SomeFormId').on('submit', function (ev) {
    
        // preventing the default action
        // : in a form, this prevents the submit
        ev.preventDefault();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some custom validation I'd like to do with jQuery. jQuery validation comes
Some Background to begin: I've implemented a custom MembershipProvider that validates a user from
I've implemented some custom fields and would like to keep the look-and-feel consistent with
I've implemented a custom view, in my view I display another set of views
I've implemented a LoginModule to perform some custom authentication, and call the authentication using
I have implemented some component. I used jsp custom tags. But I've implemented 2
We have implemented some custom tooltip-drawing code that fires on Tick events of a
Does anybody know the logic behind making DataSourceSelectArguments sealed? I've implemented a custom DataSource
I have some custom validation code, which includes a $formatter. (I store currency in
I have a spring-ws (2.0.2) service I have implemented that requires some custom elements

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.