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 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

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 185371
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 9, 20222022-06-09T21:02:39+00:00 2022-06-09T21:02:39+00:00

asp.net mvc – Jquery Validate not validating dropdownlists

  • 0

[ad_1]

I have four dropdown lists in my .net 5 core mvc view. One is populated from a list contained in the model passed to the view at runtime, the other three are populated through Json calls. All four of these DDLs are required on my form, but Jquery Validate is only catching two of them, and I cannot figure out why.

The basic code of the four DDLs is as follows. First, the two that fail validation as expected:

@* This DDL is populated from a list in the model *@    

<select id="mGroup" required>
    <option selected="selected" value="">Select Material Group</option>
        @foreach (var item in Model.groups)
        {
            <option value="@item.group" style="background-color: @item.hex_color;">
                @item.name
            </option>
        }
</select>

@* This DDL is populated from a Json call, triggered when a value is selected in the first DDL *@

<select id="mSubGroup" tabindex="7" required>
    <option value="">Select Material Group</option>
</select>

When I try to submit my form without selecting valid options in these DDLs, validation triggers and they’re assigned the class ‘input-validation-error’, which is what I want.

The two DDLs below, however, both of which are populated by Json calls, do not see this happen.

<select id="class" required>
    <option value="" selected="selected">Select Class</option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
</select>

<select id="limit" required>
    <option value="" selected="selected">Select Limit</option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
</select>

When I try to submit my form without selecting options on these DDLs, nothing happens. Their HTML remains unchanged. Even if I try selecting valid options in the first two DDLs I mentioned, these still do not get validated.

The form that contains these DDLs (and all my other inputs) is setup in code like so:

@using (Html.BeginForm(FormMethod.Post, new {id = "qForm"}))

… because the form contains multiple “submit” buttons that each trigger different form actions. In my javascript for these buttons’ click events, I call

$('#rfqForm').validate();

per the Jquery Validate documentation.

My form is also subject to MVC server-side validation in the model. These four dropdowns each feed their selected values into “Html.HiddenFor” objects connected to the postback model, which I know are not included in DOM validation. However, when I replace these hidden fields with something that is, such as a text box hidden with CSS, validation still does not trigger. This is why I’m trying to go the Jquery route.

I need to get these dropdowns validating. I hope someone can explain what’s going wrong here.

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 325 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 295 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 291 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

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.