Button remains disabled using jQuery until input has passed validation

Hey there! I've set up a form in my custom web app that allows users to update their details. Check out the code:

<g:form class = "updateCustomerClient" controller="customerClient" action="updateCustomerClient" id="${cus.id}">

    <div style="width:100%; padding-top: 50px; margin-right: auto; margin-left: auto; text-align: center">
        <div style = "height: 50vh; width: 50%; margin-left:auto; margin-right:auto;">

            <div>
                %{-- Table for customer client --}%
                <table class="table table-striped" id="table t1">
                    <colgroup>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>

                    <tr>
                        <th colspan="5" style="height: 40px;">
                            <h6 style="font-weight: bold; margin-left: 40px;">
                                <g:link action="index" controller="customer">All Customers</g:link>&nbsp;>>&nbsp;
                                <g:link action="index" controller="customerClient">${customers.name} clients</g:link> &nbsp;>>&nbsp;
                                <a href="#" onclick="goBack()">${cus.clientName}</a>&nbsp;>>&nbsp;EDIT
                            </h6>
                        </th>
                    </tr>

                    <tr>
                        <th colspan="5" style="height: 40px; text-align:center;background-color:lightseagreen"><h6 style="font-weight: bold">EDIT CUSTOMER CLIENT</h6></th>
                    </tr>

                    ...

                    </thead>
                </table>

            </div>

        </div>

    </div>
</g:form>

Additionally, here's the jQuery validation script that ensures proper inputs:

    $.validator.addMethod("lettersonly", function(value, element) {
        return this.optional(element) || /^[a-z\s]+$/i.test(value);
    }, "Please provide only alphabet");

    $('.updateCustomerClient').validate({
        rules: {
            clientname: {
                lettersonly: true
            },
            zendeskApiAuth: {
                email:true,
                required:true
            }
        },
        messages:{
            clientname:{
                required:''
            },
            clientchannelid:{
                required:''
            },
      
            zendeskApiAuth:{
                required:''
            }
         
        }
    });

To address the issue of the Submit button being disabled prematurely, you can use the following code snippet that enables the button when a valid input is detected:


    $("#zendeskApiAuth").on("keypress", function(){
        if($(".updateCustomerClient").valid())
        {
            $(".btn-reset").removeAttr("disabled");
        }
    });

With these tweaks, your form should now work smoothly without restricting user submissions unnecessarily!

Answer №1

I have discovered a solution:

 $('.updateCustomerClient input').on('keyup blur', function () { 
        if ($('.updateCustomerClient').valid()) {          
            $('.submit-button').prop('disabled', false);        
        } else {
            $('.submit-button').prop('disabled', 'disabled');  
        }
    });

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

Get rid of the "clear field" X button for IE11 on Windows 8

After trying out the suggestions provided in Remove IE10's "clear field" X button on certain inputs? .someinput::-ms-clear { display: none; } I successfully removed the X button on IE 11 running on Windows 7, but unfortunately it didn&a ...

stream a song with a font awesome symbol

Can an audio track be played using a font awesome icon, such as displaying the song name (mp3) with a play icon right next to it? When users click on the play icon, can the track start playing and be paused or stopped at will? The list will consist of app ...

Create a complete duplicate of a Django model instance, along with all of its associated

I recently started working on a Django and Python3 project, creating a simple blog to test my skills. Within my project, I have defined two models: class Post(models.Model): post_text = models.TextField() post_likes = models.BigIntegerField() post_ ...

Storing Ember.js Views for Faster Loading

Exploring the features of AngularJS and Ember, I am curious to know if Ember has the capability to cache views instead of just loading/reloading them. For instance, if I have tabs with templates like "abc.html," "def.html," and "ghi.html," can I create div ...

What is the best way to incorporate (+/-) buttons to increase or decrease numbers in this code snippet?

Hey everyone, I hope you're all doing well! I need some assistance in transforming this quantity picker from a dropdown to have buttons like the one shown here with plus and minus symbols: https://i.stack.imgur.com/O0uUa.png I would like to impleme ...

.scss compiling with errors

Recently, I embarked on a new Vue(3) project. Within this project, I have set up some basic styling in the App.scss file and created a HomeView.vue with a corresponding HomeView.scss file (located in the /src/views/Home directory). The styling from both fi ...

Can anyone tell me how to retrieve the value of {{org}} in this situation?

<head> <title>My Unique Page</title> </head> <body> <input type="text" ng-model="selectedOrg" ng-show="!isSuperAdmin" readonly /> <select id="nameOrg" ng-model="selectedOrg" ng-cha ...

Transform current JSON data into formatted JSON format using JavaScript or TypeScript

I have a JSON structure that needs to be reformatted in order to meet the requirements of an external service. Although the current format is complex and cannot be altered, I need to modify it to match the desired output for the external service. Current ...

Getting the start of a day for a specific date in JavaScript while considering the timezone

I'm having trouble determining the start of a day while factoring in timezones using javascript. Consider this example: var raw_time = new Date(this.created_at); var offset_time = new Date(raw_hour.getTime() + time_zone_offset_in_ms); // Th ...

Is there a way to apply a consistent border to both the input radio button and its corresponding label once the radio button has been selected

CSS: <div class="form-check fs-3 mb-3"> <input id="first_question" name="first_question" type="radio" value="n"> <label for="first_question">no</label> </div> Is ...

Converting multiple rows of data from MySQL into JSON format

Currently, I am working on a project that involves displaying multiple rows of MySQL JSON data in an HTML table using PHP and jQuery. The process includes input from a search box on the front end. The layout of my HTML table on the search page is structur ...

An alternative solution for supporting Edge Chromium is utilizing synchronous AJAX requests within the beforeunload event

While attempting a synchronous ajax request during the beforeunload event, I encountered an error stating that synchronous ajax requests are not supported in chromium browsers during page unload events. I am seeking alternatives for making a synchronous a ...

Generating a QR code with a web link in Node.js

Currently, I am immersed in a project that requires me to generate a QR code with specific information using NodeJS. To kick things off, I've set up a canvas in HTML and transferred it to NodeJS. <canvas id="canvas" width="300" height="300">& ...

Utilize features from both angular-strap and ui-bootstrap to enhance your project

Is it possible to efficiently utilize components from both angular-strap and ui-bootstrap without encountering conflicts that could potentially disrupt the application's functionality? For instance: Opt for a customized version of ui-bootstrap that ...

Using urllib.urlopen in place of javascript

I'm curious if there is a Javascript module that functions similarly to Python's urllib. Specifically, I am looking for something along the lines of: urllib.urlopen(url, data) This function would return an object that allows for a blocking fetc ...

Vaadin DropDown list showcasing options with unique identifiers

My current issue revolves around a ComboBox feature that allows users to select contacts from their contact list. Although the ComboBox displays contact names, it lacks the ability to directly map to the true contact as it requires the contact ID. I am str ...

Prevent the movement of the first column in a table when rearranging rows up or down by utilizing

Feeling a bit stuck here, can't seem to figure out what I've missed. I've managed to move up or down a row in a table, but I need the value of the cell in the first column to remain unchanged. Here's my code: This is my HTML file: &l ...

Issues with the styling of HTML code

Our website features a main menu with submenus that are intended to be displayed only when hovering over the main menu. However, upon loading the site, the submenu is already visible causing an issue. We need the submenu to appear only when the main menu i ...

Extracting information from within Ajax's Jsonp

How can I retrieve data from the Ajax function(result)? Why isn't this app working? Please assist me. function star(a) { var res; $.ajax({ url: 'https://api-metrica.yandex.com/analytics/v3/data/ga?end-date=today&ids=ga%3A35 ...

Encountering issues with accessing the clientWidth and clientHeight references of the DOM in Vue

Issue with 'clientWidth' and 'clientHeight' properties on Vue and Element types. <div class="invoice-step-detail" id="invoice" ref="invoice"> @Component({ name: 'CreateInvoice', co ...