Coping with validation problems across multiple pages in a form-linked Datatable

I have utilized a datatable to create a table where each row contains either an input or select field, with pagination across multiple pages.

The problem arises when the datatable renders 10 rows of HTML elements by default and jQuery validation renders per page as HTML.

I am seeking a solution to implement validation for all cells across all paginations (pages) using jQuery.

    
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">
<body>
   <table id="banklist">
   <tr>
     <td>
         <input id="bn_0" name="bd[0][bn]" placeholder="Enter Bank Name" value="testbank" aria-required="true" class="valid" aria-invalid="false">
     </td>
     <td>
         <select id="sts_0" class="sts" name="bd[0][sts]" aria-required="true"&rt;
                    <option value="">Select Status</option>
                    <option value="Y" selected="">on</option>
                    <option value="N">off</option>
                </select>
     </td>
   </tr> 
<tr>
  <td> Another 100 rows with td inputs/selects </td>
</tr>
</table>
</body>
    </style>
            <script type="text/javascript" src="resources/js/list_newbank.js"></script>
            <script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
         $(document).ready(function() {
                    $('#banklist').DataTable({
                        scrollX:        true,
                        scrollCollapse: true,
                    });
     });

 

https://jqueryvalidation.org/ jQuery Validation:

$("#banklist").validate({
                    errorPlacement: function(error, element) {
                        var ele_name = element.attr('name');
                        console.log(ele_name);
                        $('.valid').attr('style','border : 1px solid #c2bfbf !important');
                        if($('input,select').hasClass('error')) {
                            //$('label.error').remove();
                            $('input.error, select.error').attr('style','border : 1px solid red !important');
                            error.appendTo( $('.error[name="'+ele_name+'"]').parent('td'));
                        }
                }
  });

Answer №1

Have a look at the ajax method. Here is an example of how I implemented it to solve a similar issue:

$('#dt-all-orders').DataTable({
    "ajax": "ajax_files/dt_get_all_orders.php",
    "language": {
        "url": "js/datatables/datatables.lang.ua.txt"
    },
    "initComplete": function () {
        $('[data-toggle="popover"]').popover();
    },
    "columnDefs": [
        {width    : "30px", targets: [0]},
        {width    : "120px", targets: [2]},
        {width    : "120px", targets: [3]},
        {width    : "120px", targets: [4]},
        {width    : "120px", targets: [5]},
        {width    : "80px", targets: [6]},
        {className: "text-center", targets: [0, 2, 3, 4, 5]},
        {className: "td-actions text-center", targets: 6},
    ],
    "aoColumns": [
        null,
        { "bSortable": false },
        null,
        null,
        null,
        null,
        { "bSortable": false }
    ],
    "lengthMenu": [
        [10, 25, 50, 100],
        [10, 25, 50, 100]
    ],
    "stateSave": true,
    "deferRender": true,
    "order": [
        [0, "desc"]
    ],
});

However, for this scenario, you will need to manually create all columns and employ a php file with an sql query.

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

Prevent the table cell width from expanding beyond the content size

Is there a way to achieve this layout without relying on Javascript? Imagine having a <table> with an unknown width in the first column. The overall <table> width is set to 100% to allow other columns to resize accordingly, but is it possible ...

Hide a div when multiple classes are filtered using jQuery

I have several divs with the class .item. When the user clicks on the Classfilter submit button, all .item elements that also have at least one class from the dateClasses array (for example ['28.09.2015', '29.09.2015']) should be hidden ...

Using pjax in Rails 3.1, the redirect_pjax_to method will only render plain text content

Recently, I tried integrating the pjax-rails gem into one of my projects. However, when utilizing the redirect method provided by the gem, I noticed that the browser was rendering the response as text instead of executing it as JavaScript code. It seems l ...

Two sets of scrolling bars

Having an issue with my JSFIDDLE parallax effect causing two scrollbars in the result. How can I ensure there is only one scrollbar for all my content? Here is some of the HTML code: <div id="intro"> <p>Sed uelit, sed quia...</p> </ ...

Limiting the scope of a CSS style to only apply to a specific element and all of its child

Today, I am encountering an issue with restricting the application of CSS. The <div class="parent"> <div id="childWithNoCss"> <p>No css</p> </div> <div id="childWithCss"> <p>Apply css</p> </div> </ ...

A step-by-step guide on changing the class of a focused contenteditable element with a button click using jQuery

I need assistance changing the class of an element within a contenteditable div. Here is my current code: <button>swap class</button> <div contenteditable="true"> <h1 class="line-height-1">Your Headline Here</h1> </di ...

Bootstrap 4: Ensuring consistent height for all rows

I'm having trouble creating a preloader with rows. I want to divide my grey rectangle into 3 rows, each with 33% height. Here's what I need: In the first row, a SVG logo In the second row, a loader In the third row, some text Here's the ...

Steps to disable ajax global setting when making an ajax call in a kendo grid

When working with MVC 5 in the _layout page, I have incorporated .ajaxStart and .ajaxStop events to display a busy indicator. <body> <script type="text/javascript"> $(document).ajaxStart(function (e) { $( ...

Calling Ajax inside each iteration loop

I have encountered numerous posts discussing this topic, but the solutions I came across do not quite suit my needs. Some experts suggest changing the code structure, however, I am unsure of how to go about doing that. What I desire: 1) Retrieve a list ...

Utilize anonymous functions to reassign the button click event - JQuery

I'm dealing with a situation where I have 5 HTML buttons, each with a click event listener attached to it in the form of an anonymous function. For example: $('#button1').click(function(){ //some code }); At a certain poin ...

What could be causing my Ajax success function to never fire?

My issue is that my $.ajax success function is not triggering. I simply need to execute a PHP file without passing or retrieving any values. I found an alternative method for reading values, but it cannot run because the function must be placed within th ...

The tablix feature in SSRS seems to be having trouble capturing the text generated by dynamic SQL when it comes to grouping

I am encountering an issue in SSRS where I have created a dynamic SQL with a column populated from a case statement. The SQL query successfully populates the column in the database result. However, when I use it in a tablix to create a group and sum it by ...

IE Script loading

There is a script that I have, it appends in the document like so: window.d = document s = d.createElement('script') s.setAttribute('type','text/javascript') s.setAttribute('src',options.url) d.getElementById ...

The jQuery statements are not properly executing the if and else conditions

i'm currently assessing the condition using this particular code. jQuery(document).ready(function($){ $('#uitkering_funds').hide(); $('#uitkering_funds_hoofd').hide(); $('#partner_uitkering').hide(); $('#par ...

What steps should I take to repair my database table after inputting a list of records with various IDs that all match the same name?

I am working on inserting a list of records into SQL and I want to ensure that each name corresponds to only one specific ID. However, in cases where the same name is used by two different IDs, I need to override one of them so that the ID matches the lowe ...

Can the value of a CSS class be obtained even if it is not being used?

I have an application that pulls data from a database and displays it with associated metadata that dictates the display style. Let's simplify it and say the only metadata is the size of the square it should appear in. For example: dataArray : { ...

XDomainRequest for cross-domain ajax is throwing an error that is difficult to understand - an empty error message

Here is my AJAX call to a page on a different domain: if ($.browser.msie && window.XDomainRequest) { // Use Microsoft XDR var xdr = new XDomainRequest(); xdr.open("post", "https://different-domain.aspx"); ...

CSS: Issue with rounding errors in Em units

Recently, I decided to update the CSS file for a website I'm working on by making most elements and fonts dynamic in size using the em unit instead of px. The new sizes seem to be working, but there's an issue that's been bothering me. It s ...

The div is struggling to contain the image, can anyone assist with this issue?

Greetings all! I am a beginner with CSS and currently working on my website. You can check it out at this link. I am facing an issue where the image on my site is not fitting properly and it keeps repeating. Can anyone guide me on how to fix this using CS ...

Troubles with getting Bootstrap dropdown to function on Ruby on Rails platform

I'm struggling to make the bootstrap dropdown feature work on my website. I have bootstrap installed correctly, but for some reason, the dropdown functionality is not working. I suspect it might be related to jquery, although jquery seems to be functi ...