The form submission is not affected by the jQuery dialog buttons and will proceed to submit as

I'm struggling with a form and JavaScript code interaction. In my code, when the validateDialogForm() function is called, a jQuery dialog appears under certain conditions. The issue is that the dialog only shows for a few seconds before the form continues to submit. I want the form to pause after the dialog appears and only submit when the user clicks the save button. I've tried using return false; at the end of the validateDialogForm() function to prevent the form from submitting immediately, but then the form does not submit even when the save button on the dialog is clicked. What am I missing in my code? As it stands now, the form submits regardless of the presence of the jQuery dialog.

$('#checklist_dialog').hide();

function validateDialogForm() {
  
  // JavaScript code here...
}

Answer №1

To ensure the form does not submit while the dialog is visible, you must intervene to prevent continuous submission. Only after interacting with the dialog should you proceed to submit the form legitimately.

A potential challenge arises when submitting the form triggers the onsubmit functions once more! One way to handle this is by using a flag. Refer to the following pseudocode as a guide:

<form id="orderForm"
      action="/mywebsite/order.htm"
      method="POST"
      onsubmit="return (validateOrderForm(this) && validateDialogForm(this))">
...
let real_form_submit = false;

function validateDialogForm(theForm){
  if(!real_form_submit) {
    $('#checklist_dialog').dialog({
      ...
      buttons: {
        "SAVE": function() {
          $(this).dialog('close');
          real_form_submit = true;
          theForm.submit()
        },
        "CANCEL": function() {
          $(this).dialog('close');
        }
      }
    });
  }

  return real_form_submit;
}

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

Converting canvas illustrations into HTML files

I am in the process of creating a drawing application that will be able to export into HTML/CSS/JavaScript. I plan to use this tutorial as a foundation for the drawing functionality. My goal is to take all the rectangles within the this.shapes = [] array a ...

Is there a way to incorporate content onto a webpage solely through the use of CSS and JavaScript?

Currently, I am in the process of developing a real estate website that utilizes a paid service for displaying real estate listings. The unique aspect of this setup is that my website operates as a subdomain of the main listings website, resulting in a URL ...

unique navbar color transition effect specifically for the homepage

I have successfully created a function called changeColour in my code that changes the color of the navbar when scrolling past a certain point. However, I am encountering an issue where I only want this effect to be applied on the Home page. I would like a ...

What is the best way to set up a webpage so that the left side remains fixed while allowing the right side to scroll?

Currently, I am developing a blog and aiming to position the blog posts on the left side while having the admin panel on the right. Essentially, I want both user and developer interfaces to be fully functional on one page. The developer side should be scro ...

Guide on using jQuery to incrementally cycle through an array using a button

I am facing an issue with iterating through an array of objects using a button. The iteration is skipping 2 on each click instead of moving to the very next record. Can someone help me troubleshoot this problem? Or suggest a better approach to iterate thro ...

Converting UTF-16 to UTF-8 in JavaScript: A step-by-step guide

I'm facing a challenge with Base64 encoded data in UTF-16 format. While most libraries only support UTF-8, I need to find a way to decode the data by dropping the null bytes, although I'm not sure how to go about it. Currently, I'm utilizin ...

The response from Axios in NodeJs is displaying incorrect encoding

Having some trouble executing a REST call using Axios and receiving an unexpected response. try { const response = await axios.get("https://api.predic8.de/shop/products/"); console.log(response.data); } catch (error) { console.log(`[Error] -> ...

Outcome of Request.Form when the input requested is empty

What can I do when Request.Form("myInput") is blank and causes a server error? Any suggestions on how to address this issue? Is there a method to verify if "myInput" has not been populated? ...

JavaScript error: forEach is not a function

I've encountered an issue while attempting to loop through a JSON object to extract data. Whenever I run my code, I receive this error: Type Error: element.listing.forEach is not a function. It's worth mentioning that I've used this method ...

The autocomplete feature is working, but it seems to be unable to locate any words

I have encountered an issue with the autocomplete feature, where words starting with an Uppercase letter are not being recognized properly. For example, 'Brussels': I can find it by typing in 'russels' in the searchbox, but 'Bru. ...

The variable $scope.variable_name has not been defined

Working on websites using AngularJS has been a great way for me to enhance my skills with this framework. However, I have encountered an error that I need help troubleshooting. The code in main-controller.js is as follows: (function(){ angular.module(&ap ...

The timer countdown is encountering an issue where it cannot update the 'textContent' property of a null element

I'm encountering errors with a countdown script that I can't seem to resolve. The error message is generating 1 error every second: Uncaught TypeError: Cannot set property 'textContent' of null at (index):181 (anonymous) @ (index):181 ...

Trouble getting vertical alignment to work using display:table-cell within display:table

This is my initial inquiry, so I apologize if the formatting is incorrect. Despite attempting various methods from Stack Overflow, I am still unable to properly display this content vertically centered. CSS: div.img-wrapper { display: table; height: ...

Attempting to utilize ng-click on an element that has been added using element.append() in the postlink phase?

I have been working on customizing a particular angular library to incorporate some new features. https://github.com/southdesign/angular-coverflow/blob/master/coverflow.js As part of this process, I am looking to attach click events to the elements being g ...

What is the best way to include an image in a PHP form along with additional attributes?

I've been attempting to upload an image with additional attributes in a HTML form using PHP. The code I have below somewhat works, but when I submit the form after selecting the file from a directory, I can see the file in my database BLOB column. How ...

Click on the anchor tag to reveal additional content beyond the default display

This question stems from a previous discussion on the topic at: Only show specific div with anchor In my profiles.html page, there are profiles of around 20 people all grouped under a class named "profile" and unique ids such as "example-name1", "example ...

Searching for MongoDB key names for querying and filtering purposes instead of focusing on values

My goal is to search for all keys within a collection that partially match a specific string. So far, I've only been able to check if a key exists, but it has to be an exact match. Here's the code I've used: db.collection.find({ "fkClientI ...

Conceal certain profile details on the Profile Page using the Lamba Theme

Seeking assistance from the community here. Currently using Moodle version 3.8+, paired with the Lambda theme, I have a query to address. Specifically on the Profile Page, I aim to eliminate certain elements. Typically, I would apply additional CSS with ...

Execute JavaScript function after completion of CSS animation using jQuery

I'm working on an accordion feature that uses CSS animation to expand the clicked item. The expansion is triggered by li:target. However, I'm facing an issue where when clicking on an item, the scroll position doesn't align correctly with t ...

The md-select component in AngularJS is not retrieving data from the controller as expected

I am struggling with my code that is not displaying options for md-select. This specific HTML page is not the main page of my project, but rather part of my first AngularJS application. As a newcomer to AngularJS, I would greatly appreciate any assistance. ...