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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:02:28+00:00 2026-06-12T02:02:28+00:00

Hi and thanks for taking the time to answer my question. I need to

  • 0

Hi and thanks for taking the time to answer my question.

I need to create a validation rule within the validation engine thay will not allow values of 0. (meaning at least one element has to be selected). I have a select element and the default (Please select an item) has a value of 0 because it is not required. But once a checkbox is selected I need to make it required. I cannot add the class ‘validate[required]’ because 0 is a valid value. So my question would be how to make a custom rule which will not allow values of 0 to be passed to the controller.

Thanks again

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

    I think it’s no need in custom validation. You can add required attribute with the help of jquery when checkbox is checked and remove this attribute when it’s unchecked(and also check it on document ready for first load).
    For example:

    $('#myCheckBox').click(function () {
                if ($(this).is(':checked')) {
                    $('#myDropDown').removeAttr('required');
                }
                else {
                    $('#myDropDown').attr('required', true);
                }
            });
    

    But in this case your <option> value should be empty. <option value>Please select an item</option> (as i know it’s usual behaviour of dropdownlists) . And after that jquery validation plugin will automatically validate required attribute.

    EDIT

    Alright, if you definitely should use custom validation, you can do it this way:

    1) Add you validation method( on document ready for instance)

     $.validator.addMethod("checkIfNotZero", function (value, element) {
                return this.optional(element) || ($('#checkbox').is(':checked')&&value!=0);
            }, "Please, select value");
     $.validator.addClassRules("mySpecificClass", { checkIfNotZero: true });
    

    2) Mark you dropdownlist with class="mySpecificClass"

    3) And check if $('#myDropDown').valid() where it’s necessary (or for instance call $(form).validate() in onSubmit event handler).

    I think that’s all. Hope it will help.

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

Sidebar

Related Questions

thanks for taking the time to stop by my question. Below you will find
First off good day and thanks for taking the time to answer my question.
Thanks for taking the time to answer my question. I want to check if
Hi all and thanks for taking the time to answer my question. I have
Hi and thanks for taking the time to answer my question. Appreciate it. Let's
Hi and thanks for taking the time to answer my question. I have a
Hi and thanks for taking the time to answer my question. I have a
thanks for taking the time to look at my question. I've been diving into
Thanks in advance for taking the time to read my question. I'm using MySQL
Thanks for taking time to review this question. I've been trying to fix a

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.