Error encountered in Jquery form validation: Maximum call stack size exceeded due to uncaught range error

I've been struggling with implementing Jquery form validation and keep encountering the Uncaught range error: maximum call stack exceeded. The issue occurs while using materialize CSS.

This is the specific error I am facing:

Uncaught RangeError: Maximum call stack size exceeded
at RegExp.[Symbol.replace] (native)
at String.replace (native)
at Sizzle (http://localhost:3001/bower_components/jquery/dist/jquery.js:869:26)
at Function.Sizzle.matches (http://localhost:3001/bower_components/jquery/dist/jquery.js:1405:9)
at Function.jQuery.filter (http://localhost:3001/bower_components/jquery/dist/jquery.js:2769:15)
at winnow (http://localhost:3001/bower_components/jquery/dist/jquery.js:2749:18)
at jQuery.fn.init.is (http://localhost:3001/bower_components/jquery/dist/jquery.js:2807:12)
at FormValidation.Framework.Bootstrap._getMessageContainer (http://localhost:3001/js/formValidation.min.js:10:13553)
at FormValidation.Framework.Bootstrap._getMessageContainer (http://localhost:3001/js/formValidation.min.js:10:13639)
at FormValidation.Framework.Bootstrap._getMessageContainer (http://localhost:3001/js/formValidation.min.js:10:13639)

Here is my jquery and html code snippet that triggers the error:

 <form class="col s12 m8 l6" id="frontdesk-form-validation">
                <div class="row">
                    <div class="input-field col s12">
                        <input id="first_name" name="name" type="text" class="validate">
                        <label for="first_name">Name</label>
                    </div>
                </div>
SUBMIT
        </form>
function saveEnquiry() {
                    $('#frontdesk-form-validation').formValidation({
                            framework: 'bootstrap',
                            fields: {
                                name: {
                                    validators: {
                                        notEmpty: {
                                            message: 'The name is required'
                                        }
                                    }
                                },
                            }
                        })
                        .on('success.form.fv', function(e) {
                            e.preventDefault();
                            var name = $('#first_name').val();
                            var mobile = $('#tel1').val();
                            var email = $('#email').val();
                            var message = $('#message').val();
                            var description = $('#description').val();
                            var source = $('#source').val();
                            var assignedTo = $('#assigned').val();
                            $.ajax({
                                type: "POST",
                                url: '/enquiry/add',
                                data: {
                                    name: name,
                                    mobile: mobile,
                                    email: email,
                                    message: message,
                                    description: description,
                                    source: source,
                                    assignedTo: assignedTo
                                },

                                success: function(data) {
                                    Materialize.toast('I am a toast!', 4000);
                                    return data;
                                }
                            });
                        });
                }

In addition to the previous error, another one I'm encountering is:

Uncaught TypeError: Cannot read property 'length' of undefined
at FormValidation.Framework.Bootstrap.validateField (formValidation.min.js:10)
at FormValidation.Framework.Bootstrap.validate (formValidation.min.js:10)
at HTMLFormElement.<anonymous> (formValidation.min.js:10)
at HTMLFormElement.dispatch (jquery.js:4737)
at HTMLFormElement.elemData.handle (jquery.js:4549)

If anyone can provide assistance on this matter, it would be greatly appreciated. Thank you in advance!

Answer №1

After encountering the identical issue and conducting extensive research, I realized that I had neglected to include a class called form-group in the parent container of the element being validated. Once rectified, the validation process now functions perfectly for me.

Answer №3

To start, make sure to include the post method in the form:

$(document).on('submit', '#formid', function() {
  $(this).validate({
      framework: 'bootstrap',
      fields: {
        name: {
          validators: {
            notEmpty: {
              message: 'Please enter your name'
            }
          }
        },
        email: {
          validators: {
            notEmpty: {
              message: 'Email address is required'
            }
          }
        },
        mobile: {
          validators: {
            notEmpty: {
              message: 'Mobile number is mandatory'
            }
          }
        },
      }
    })
    .on('success.form.fv', function(e) {
      e.preventDefault();
      var Formdata = $(this).serialize();
      $.ajax({
        type: "POST",
        url: '', //insert page URL here
        data: Formdata,
        success: function(data) {
          alert(data);
        }
      });
      return false;
    });
});

Answer №4

In my understanding, I have declared two variables with identical names:

= hidden_field_tag(:budget, client.id) 
.form-group
  = f.label(:budget, 'Budgeted Amount', class: 'control-label col-sm-5')
    .col-sm-19
      = f.number_field(:budget, class: 'form-control', required: true)

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

Searching for the clicked tr element within a tbody using jQuery

Here is my customized HTML table layout <table> <thead> <tr> <td class="td20"><h3>Client Name</h3></td> <td class="td20"><h3>Details</h3></td> ...

The Bootstrap menu seamlessly extends beyond the edge of the screen

Whenever I try to zoom in on my page, the navigation bar doesn't collapse as expected. Instead, it overflows off the page. This issue persists when viewing the website on mobile devices in landscape mode. Although I am using the jQuery mmenu plugin, ...

The code in the head section is not running as expected

I've been exploring the possibilities of using lambda on AWS in combination with api gateway to create a contact form for a static S3 website, all inspired by this informative blog post: https://aws.amazon.com/blogs/architecture/create-dynamic-contact ...

Trouble displaying REACT.jsx in browser

I'm currently learning React and struggling to get it running smoothly. HTML function Person(){ return ( <div class="person"> <h1>Max</h1> <p>Your Age: 28</p> </div> ); } ...

Determine the precise quantity of kids using jQuery

When attempting to determine the exact number of child elements and then apply a specific class to another element with a matching class, keep in mind that it may not be the immediate parent element where this action needs to be executed. $(".test").eac ...

Dealing with numerous file uploads: At what point does the array update when you add an item to it?

I am facing an issue with creating a file input that allows for multiple CSV files to be uploaded simultaneously. Each file goes through data cleaning functions and is then added to a global array. However, the array does not seem to update even though it ...

Tips for creating extra space on both sides of a Bootstrap container

I am currently working on creating some extra spacing on the left and right of a Bootstrap container. My current approach involves using a 'fluid' container/section and adding margin on both sides to create the desired space. However, the issue ...

Divide the division inside the box by clicking on it

I am looking to create a unique div with a random background color and a width of 100px. Additionally, I want to have a button that, when clicked, will split the original div into two equal parts, each with its own random background color. With each subs ...

Organize JSON data based on the timestamp

What is the most effective method for sorting them by timestamp using jquery or plain JavaScript? [{"userName":"sdfs","conversation":"jlkdsjflsf","timestamp":"2013-10-29T15:30:14.840Z"},{"userName":"sdfs","conversation":"\ndslfkjdslkfds","timestamp" ...

The HTML is not rendering as planned

I have 2 files, test.html <!DOCTYPE html> <head> <title>test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="./test/jquery.min.js"></script> </head> <body> ...

Tips on Enhancing a Fetch Query in Laravel with the Help of Ajax

I am encountering difficulty fetching a list of cities with over 40,000 entries. The main issue is the lack of optimization as my browser becomes unresponsive while loading the city data. Within my Laravel Controller, the code snippet below showcases how I ...

Ways to modify the final sum exclusively for a single table

I am currently struggling to figure out how to calculate only the grand total of the first table using just one jQuery/JavaScript script. The code I am referencing is from: Below is the code snippet: <!DOCTYPE html> <html xmlns="http://www.w3 ...

Background image specifically for the Fullcalendar sun component

When setting a background image for Sunday in the month view, I noticed that the day "Sunday" in the header is also getting the same background. The CSS for the table thread has classes like .fc-sun and .fc-mon set as well, but I'm not sure how to rem ...

Ways to dynamically navigate to the end of a webpage following an AJAX request

My jQuery ajax code is functioning properly and displaying the response on the page. However, I am facing an issue with scrolling to the bottom position of the window after displaying the response. To achieve this, I have implemented the following jQuery ...

Ajax code in Objective C causing screen to stall

Stepping into the iOS world and diving into Objective-C programming is a new journey for me. I am currently working on developing a basic iOS app for both iPad and iPhone, starting off with an initial login screen. At times, everything seems to work well, ...

Adjusting the appearance of internal components with material-ui icons

Currently working on a project using react and material-ui where I am looking to customize the styles of specific elements within components. An example is the ListItem component which includes primaryText, leftIcon among others, and my goal is to modify t ...

Listening for a click event on a newly added element using JQuery

I am relatively new to using JQuery and I have encountered an issue with adding a click event listener for a dynamically created button. When the user clicks on the first button, my function successfully adds a second button to a div. However, I am facing ...

What is the best way to overlay several hidden links on a single image using HTML?

Currently working on a project using Flask and I am interested in creating an interactive image where clicking on different sections will navigate to unique links. Is this achievable? Any guidance or resources on how to implement this feature would be mu ...

Unable to import JavaScript file from "static" directory in Flask environment

Having trouble importing mainfirst.js onto my HTML page. I've attempted the following methods: <script src="../../../static/assets/js/main.js"></script> <script type="text/javascript" src="{{ url_for('static',filename=' ...

What is the method for altering the choices within one selection based on the selection made in another dropdown menu

Welcome to the code snippet! <select id="type"> <option value="item1">item1</option> <option value="item2">item2</option> <option value="item3">item3</option> </select> <select id="size"> <option v ...