Validation conditions with ASP.Net Razor Pages

Working with ASP.Net Core 2.2 razor pages and Bootstrap 4, where users input family member information. The form serves both for adding and editing members, calling different handlers. If an email is not provided, a modal confirmation is displayed. Currently, when an email is provided, the submission works correctly. However, when no email is provided, the modal appears but clicking 'Yes' does not trigger any action, and there are no messages in the debug console.

 function submitForm() {
        if ($("#email").val() === "") {
            $('#modalNoEmail').modal();
            return false;
        } else {
            document.getElementById("frm1").submit();
        }
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
    <div class="col-md-8 order-md-1">    
      
        <form method="post" onsubmit="return submitForm()" id="frm1">

            <div class="modal" tabindex="-1" role="dialog" id="modalNoEmail">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title"> No Email Specified</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <p>
                                You have not entered an email address. Confirm proceeding without entering an email address?
                            </p>
                        </div>
                        <div class="modal-footer">
                            @if (Model.Subscriber != null && Model.CountOfSubscribers > 0)
                            {
                                <button class="btn btn-primary btn-secondary btn-block button" type="submit" asp-page-handler="Edit">Yes</button>
                            }
                            else
                            {
                                <button class="btn btn-primary btn-secondary btn-block button" type="submit" asp-page-handler="Add">Yes</button>
                            }
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
                        </div>
                    </div>
                </div>
            </div>
            


            <div class="row">
                <div class="col-md-6 mb-3">
                    <label>First name</label>
                    <input asp-for="Subscriber.FirstName" class="form-control">
                    <span asp-validation-for="Subscriber.FirstName" class="text-danger"></span>
                </div>
                <div class="col-md-6 mb-3">
                    <label>Last name</label>
                    <input asp-for="Subscriber.LastName" class="form-control">
                    <span asp-validation-for="Subscriber.LastName" class="text-danger"></span>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label>Email</label>
                    <input asp-for="Subscriber.Email" class="form-control" id="email">
                    <span asp-validation-for="Subscriber.Email" class="text-danger"></span>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    @if (Model.Subscriber != null && Model.CountOfSubscribers > 0)
                    {
                        <button class="btn btn-primary btn-lg btn-block button" type="submit" asp-page-handler="Edit">Save</button>

                    }
                    else
                    {
                        <button class="btn btn-primary btn-lg btn-block button" type="submit" asp-page-handler="Add">Add Member</button>
                    }
                </div>               
            </div>

        </form>
        </div>
    </div>
</div>

Answer №1

It appears that there may be a misconception here. It seems that there is a never-ending loop in your code. When you submit back to the handler, your email field is empty, causing the modal window to be called again.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Charge me at a later date directly from the shopping cart

We need to integrate the BILL ME LATER feature into our shopping cart. The challenge is to have a scenario where customers can add products to their cart and then choose from three options for checkout: 1. Regular Checkout 2. PayPal Checkout 3. BILL ME LAT ...

What is the method for gaining access to variables and functions within bundle.js?

Hello, I am trying to figure out how to access variables in bundle.js. I want to experiment with variables and functions on the client side using JavaScript, but I'm having trouble calling them in index.html or the Chrome console. I use browserify to ...

Using Angular5 to extract coordinates from the Google Maps v3 API when a map "click" event occurs

Can anyone assist me with retrieving coordinates from a click event on a map? Here is the desired result: Link Below is the code I have so far: import { Component, OnInit } from '@angular/core'; import { ViewChild } from '@angular/core&ap ...

What is the reason why modifying a nested array within an object does not cause the child component to re-render?

Within my React app, there is a page that displays a list of item cards, each being a separate component. On each item card, there is a table generated from the nested array objects of the item. However, when I add an element to the nested array within an ...

Error encountered: Attempting to use a class as a function in vue-socket.io is not permitted

I am developing a Vue chrome extension where I am attempting to implement web sockets using vue-socket.io. I have followed the basic instructions on deploying a node server with express and socket.io on Heroku, but I am encountering issues with the conne ...

Troubleshooting Next.js and NextAuth.js Authentication Redirect Issue

I am experiencing a problem with authentication in my Next.js application using NextAuth.js. The issue specifically pertains to the redirection after successful login. Here is an overview of my setup: NextAuth.js Configuration (app/api/auth/[...nextauth.js ...

Encountering some difficulties while setting up my development tool (specifically webpack)

I have embarked on a journey to learn modern JavaScript with the help of Webpack and Babel. As a beginner in this field, my instructor is guiding me through the principles of modern JavaScript by building an app called Forkify - a recipe application. While ...

What is the best way to use identical styles for 2 different classes at separate breakpoints?

Is it possible to apply a chunk of (S)CSS to two different elements in two different breakpoints to avoid redundancy? I am using Bootstrap 4.6. <div class="one"> <div class="content">Something</div> </div> & ...

Utilizing the JavaScript map method to structure API response data

Here is the JSON data I have: { "result": [{ "name": "a", "value": 20, "max": 100, "sale_value": [{ "no": 1, "name": "aaaaa", "price": 200 }, { "no": 2, ...

Changing the Size of X-Axis Labels Font in a Line Chart Using ChartJS

Struggling with adjusting the font size of x-axis labels in my line chart design using ChartJS. I've attempted to set the x-axis ticks to my desired size, but the font size remains unchanged: options:{ scales:{ xAxis: [{ ...

Signs to look for that a text box is currently being modified

Have you heard of the Hot Virtual Keyboard app? It's an onscreen keyboard that you can find at . One interesting feature of this keyboard is a setting where you can choose to have the keyboard automatically show up whenever the text cursor is visible: ...

An AngularJS-powered dynamic navbar

Apologies if my explanation is unclear, but I am struggling to find a simple way to convey the following information. I have set up a navigation bar that displays different categories of articles. These navigation items are pulled from a database and can ...

Exploring JSON data in React applications

Below is the code I am currently working with: export class Highlights extends React.Component { render() { return ( <div> {JSON.stringify(this.props.highlights_data.data)} </div> ) ...

Not sure how to configure the settings for Firebase Firestore within the admin.firestore module

When trying to set an option at admin.firestore, I couldn't find the set method. It should be done like this: const settings = {timestampsInSnapshots: true} admin.firestore.settings(settings) However, I encountered a TypeError: Firestore.settings is ...

What is the reason behind the Placeholder not functioning in IE8?

Whenever I trigger the onblur event on an input of type "password", it will hide both the placeholder text and the input itself. Check out the GitHub link for this plugin ...

Retrieving the checkbox value from a dropdown selection

I'm stuck and feeling lost here - I must be missing something obvious. Any help will be greatly appreciated! (I am a beginner in html and javascript) I have created a dropdown menu with an unordered list of items populated from JSON data. Here is the ...

Looking to implement v-model with a group of checkboxes in a Custom Component in Vue3?

The code snippet below demonstrates the power of v-model. By checking and unchecking checkboxes, the checkedNames array will automatically add or remove names. No need to manually manipulate the array with push, slice, or filter operations. const { ref ...

I want to create a Bootstrap 4 card deck that includes expand/collapse functionality for its content. The expanded content should only impact the current

I am experiencing an issue with my card decks and expand/collapse functionality. Currently, when I expand one card in the deck, all the other cards in the row also expand, leaving a large blank area. This becomes problematic especially when the content is ...

Creating a dropdown menu with data loaded dynamically using ajax and json, all without relying on jquery

I am looking to populate a few select menus using JSON data retrieved from my PHP script. Each select menu should display different values based on the selections made in the other menus. While I understand how to clear and fill a select menu using JavaScr ...

Emulating a Javascript API request

I'm looking to practice simulating API calls for a VueJS application. Currently, I am fetching data from a hardcoded JSON file that I've created. Within my App.vue: <template> <p>{{ teams.yankees.city }}</p> // Output will b ...