简体   繁体   English

formvalidation.io 外部提交按钮

[英]formvalidation.io external submit button

Im working with formvalidation.io and have created a form and want to submit the form with a button that is not contained within the form element.我使用 formvalidation.io 并创建了一个表单,并希望使用不包含在表单元素中的按钮提交表单。 Quick example below:下面的快速示例:

<form id="form1">
  <input name="test" type="text" required />
</form>

<button type="submit" form="form1" value="Submit">Submit</button>

Pressing the button will validate the form, but will not continue to submit the form.按下按钮将验证表单,但不会继续提交表单。 Including the same button inside the form element will work perfectly fine.在表单元素中包含相同的按钮将工作得很好。 I'm assuming this is a bug in the formvalidation.io library, but I want to post here to make sure I'm not doing something stupid first.我假设这是 formvalidation.io 库中的一个错误,但我想在这里发布以确保我没有先做一些愚蠢的事情。

Any thoughts?有什么想法吗?

whoops, thought i already answered this.哎呀,以为我已经回答了这个。 i had it confirmed on the formvalidation.io forums that this is a work in progress with their library so this is the workaround i came up with.我在 formvalidation.io 论坛上确认这是他们图书馆正在进行的一项工作,所以这是我想出的解决方法。

        // select all buttons which have the form attribute
        $('[form=' + $(this).attr('id') + ']').click(function (e) {
            // prevent default functionality
            e.preventDefault();

            // execute form validation if necessary
            if (form.data('formValidation') != null) {
                $('#' + $(this).attr('form')).data('formValidation').resetForm();
                $('#' + $(this).attr('form')).data('formValidation').validate();
            }

            // submit your form however you normally submit it
            form.ajaxSubmit(options);
        });

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

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