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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:09:49+00:00 2026-06-13T23:09:49+00:00

I’m using jQuery with the validate plug-in to validate a form. I’m also using

  • 0

I’m using jQuery with the validate plug-in to validate a form. I’m also using jQuery-ui’s autocomplete to provide a list of acceptable values for one of the fields. Two fields, prov_type and prov_date control the content of the autocomplete list. prov_type is a radio button and prov_date is a text input with datepicker attached.

Goals

  1. Show message from failed hasantecedent rule in a different place from normal rules
  2. Show hasantecedent failure message only once, even though it applies to 2 fields

Problem

I have added prov_type and prov_date to $.validator.groups as “hasant” which accomplishes the second goal. The issue is that they are really only a group for the hasantecedent rule. Any other rules applied to them (e.g. date validation on prov_date) should really act as though the elements weren’t grouped. I think this probably can be addressed either in errorPlacement or in showError but I can’t figure out how.

Ideas?

Code

validation defaults

$.validator.setDefaults({
    debug: true,
    ignore: ":hidden", // do not validate form fields in invisible sections
    focusCleanup: true,
    errorPlacement: function(error, element) {

        //something here to determine for placement of group rules?

        if ( element.is(":radio") ) {
            error.appendTo( element.parent().next().next() );
        }else if(element.is(":checkbox") && element.parent().is('li')){
            error.insertBefore(element.closest("ul.horiz"));
        }else{
            error.appendTo(element.parent());
        };
    },
    success:'checked',// set this class to error-labels to indicate valid fields
    validClass:'checked'//set this to same so valid class will be removed from fields that become errors
});

hasantecedent rule

$.validator.addMethod("hasantecedent", function( value, element ) {
    set_possible_antecedents();
    var type=$('input[name="prov_type"]:checked').val();

    var r = $('#prov_date').data(type).length;
    if(r){
        $('.antecedent',$('#'+ type)).removeAttr('disabled');
    } else {
        $('.antecedent',$('#'+ type)).attr('disabled','disabled');
    }

    return r;
}, 'No fish are available for the current provenance date.');

form validation

$("form[name='provenance']").validate({
    onkeyup: function(element, event){ //no keyup validation for fields with UI widgets
        if(jQuery.inArray( element.name,['prov_date','dam', 'sire','reuse'])>-1) return;
         $.validator.defaults.onkeyup.call(this, element, event);
    },
    groups:{hasant: 'prov_type prov_date'},
    rules: {
        prov_type: {hasantecedent: {depends: function(e){ return jQuery.inArray( $('input[name="prov_type"]:checked').val(),['cross','reuse']) > -1;}}},
        prov_date: {
            dateCan:true,
            hasantecedent: {
                depends: function(e){return jQuery.inArray( $('input[name="prov_type"]:checked').val(),['cross','reuse']) > -1;}
            }
        },
        fish_id: { required: true, pkey: true},
        dam_id: {
            required: function(e) {return $('input[name="prov_type"]:checked').val()=='cross';},
            pkey: true
        },
        sire_id: {
            required: function(e) {return $('input[name="prov_type"]:checked').val()=='cross';},
            pkey: true
        },
        dam: {
            required: function(e) {return $('input[name="prov_type"]:checked').val()=='cross';},
            isantecedent: {
                depends: function(e){return $('input[name="prov_type"]:checked').val()=='cross';}
            }
        },
        sire:{
            required: function(e) {return $('input[name="prov_type"]:checked').val()=='cross';},
            isantecedent: {
                depends: function(e){return $('input[name="prov_type"]:checked').val()=='cross';}
            },
        },
        dam_count: {
            digits: function(e) {return $('input[name="prov_type"]:checked').val()=='cross';},
            min:0
        },
        sire_count: {
            digits: function(e) {return $('input[name="prov_type"]:checked').val()=='cross';},
            min:0
        },
        supplier_id:{
            required: function(e) {return $('input[name="prov_type"]:checked').val()=='delivery';},
            pkey: true
        },
        removal_id:{
            required: function(e) {return $('input[name="prov_type"]:checked').val()=='reuse';},
            pkey: true
        },
        removal: {
            required: function(e) {return $('input[name="prov_type"]:checked').val()=='reuse';},
            isantecedent: {
                depends: function(e){return $('input[name="prov_type"]:checked').val()=='reuse';}
            }
        },
    }
});
  • 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-13T23:09:49+00:00Added an answer on June 13, 2026 at 11:09 pm

    What I ended up having to do is remove the hasant group, add a static #hasant div where the message could go, and add a toggle vis to the hasantecedent rule. Like this:

    javascript

    $.validator.addMethod("hasantecedent", function( value, element ) {
        set_possible_antecedents();
        var type=$('input[name="prov_type"]:checked').val();
        var r = $('#prov_date').data(type).length;
        if(r){
            $('input.antecedent').removeAttr('disabled').removeClass('warning');
            $( "#hasant" ).hide();
        } else {
            $('input.antecedent').attr('disabled','disabled').addClass('warning');
                    $( "#hasant" ).show();
        }
        return r;
    },  ' ');
    

    css

    #hasant {
        display:none;
        color:#C7252B;
        border: 2px solid #C7252B;
        position: absolute;
        top:100%;
        left:65%;
        width: 15em;
        padding: 1em;
    }
    

    html

    <div id='hasant'>No fish are available for the current provenance date.</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.