javascript - 验证失败时禁用按钮

标签 javascript php jquery validation laravel-4.2

我有一张表单,其中有一个提交按钮, 我想禁用提交按钮,直到所有验证都为真。

目前,当一个验证为 true 时,按钮就会启用。 (甚至其他字段也有红色错误消息。)

<script>           
     $(document).ready(function() {
                    $('[data-toggle="tooltip"]').tooltip();
                    $('#payment-form').formValidation({
                      framework: 'bootstrap',
                      trigger: 'change',
                      fields: {
                        first_name: {
                          validators: {
                            notEmpty: {
                              message: 'The First Name field is required and cannot be empty'
                            }
                            // regexp: {
                            // regexp: /^[a-z\\s]+$/i,
                            // message: 'The first name field can consist of alphabetical characters and spaces only'
                            // }
                          }
                        },
                        last_name: {
                          validators: {
                            notEmpty: {
                              message: 'The Last Name is required and cannot be empty'
                            }
                            // regexp: {
                            // regexp: /^[a-z\\s]+$/i,
                            // message: 'The Last name can consist of alphabetical characters and spaces only'
                            // }
                          }
                        },
    }
                      });


                 }).on('success.form.fv', function (e) {
                  $('#continue_btn').attr('disabled','false');
                   e.preventDefault();

                    });
                    var i = 0;
                    var l=0;

                    $('#zip_code').keydown(function()
                    {

                      var country_check = $('#country').val();
                      if(country_check=='India')
                      {
                        $('#zip_code').attr('maxlength', '6');
                      }
                      else
                      {
                        $('#zip_code').attr('maxlength', '10');
                      }

                    });
</script>

如何做到这一点?

最佳答案

在 formValidation 中设置以下属性,如表单设置中所示: http://formvalidation.io/settings/

$('#data_form').formValidation({
...
   button: {
       selector: "#id_submit_btn",
       disabled: "disabled"
   }
....
});

关于javascript - 验证失败时禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36790823/

相关文章:

javascript - 如何在 Android 10 上使用 Cordova 创建文件夹?

javascript error : periodLookup[periodStr] is undefined, 为什么抛出这个错误?

javascript - 使用 Javascript FileReader API 一次读取多个文件

PHP 绑定(bind) 'bigint' 数据类型(MySQLi 准备语句)

javascript - 编写原型(prototype)来检查字符串是否为大写

php - Youtube API - 像一个视频 PHP

php - MySQL PHP 记录检查

php - Ajax 代码仅适用于第一个 <li>

jquery - 以网格布局排列图像

jQuery ajax 完成 : Is there a way to tell which Javascript function executed the ajax call?