简体   繁体   English

formvalidation.io 中的表单验证在多个表单之间发生冲突

[英]Form validation in formvalidation.io conflict between multiple forms

I'm using formvalidation.io and I have 2+ forms on the same page.我正在使用 formvalidation.io 并且在同一页面上有 2 个以上的表单。

When I submit form 1, the submit button is disabled if form 2 is not valid, even though form 1 is valid.当我提交表单 1 时,如果表单 2 无效,即使表单 1 有效,提交按钮也会被禁用。

JS: JS:

$('form').formValidation({
    framework: 'bootstrap',
    trigger: 'keyup blur',
    fields: {
        required: {
            selector: '[validator="required"]',
            validators: {
                notEmpty: {
                    message: 'This is required'
                }
            }
        }
    })
};

HTML: HTML:

<form id="form-1">
  <input type="text" validator="required">
  <input type="text" validator="required">
  <input type="submit" value="Submit">
</form>

<form id="form-2">
  <input type="text" validator="required">
  <input type="text" validator="required">
  <input type="submit" value="Submit">
</form>

Make sure to use the proper id of your form:确保使用表单的正确 id:

<form id="form-1"></form>

$('#form-1').formValidation({
        ...
});

Ref: http://formvalidation.io/examples/cant-submit-form-after-validation/参考: http : //formvalidation.io/examples/cant-submit-form-after-validation/

我通过将其全部设为一种形式并使用 javascript 禁用项目并更改表单的操作来解决它。

this is old but I'm today on this :)这是旧的,但我今天在这个:)

You can manually validate each form and submit it when form is valid.您可以手动验证每个表单并在表单有效时提交。

More info - https://formvalidation.io/guide/examples/validating-form-manually/更多信息 - https://formvalidation.io/guide/examples/validating-form-manually/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM