简体   繁体   English

上一个按钮没有表单验证

[英]No form validation on previous button

I have a multiple pages form where people can press next and previous .我有一个多页form ,人们可以在其中按nextprevious The form validates when trying to click next but it also validates when they click previous , which shouldn't be the case.表单在尝试单击next时验证,但在单击previous时也会验证,这不应该是这种情况。

I've searched on Google and used some solutions provided by different websites such as class="cancel" or formnovalidate="formnovalidate" but nothing has worked for me so far.我在谷歌上搜索过并使用了不同网站提供的一些解决方案,例如class="cancel"formnovalidate="formnovalidate"但到目前为止没有任何效果。

These are my two buttons who are both in a form这是我的两个按钮,它们都在一个表单中

<button data-role="prevbutton" class="btn btn-secondary pull-left">Previous</button>
<button data-role="nextbutton" class="btn btn-primary">Next</button>

There is no simple JS code that calls a function but more like this:没有调用函数的简单 JS 代码,而是更像这样:

flow.isBelgianResidentChangeHandler = function(isBelgianResident) { 
if (isBelgianResident) { 
$('[data-role="nextbutton"]').attr('disabled', false); 
} else { 
$('[data-role="nextbutton"]').attr('disabled', true); 
} };

It's hard to know without seeing your JavaScript code, but it could be because the default behavior of button elements in a form are to be submit buttons.没有看到您的 JavaScript 代码很难知道,但这可能是因为表单中按钮元素的默认行为是提交按钮。 So, whichever button you pressed, it would still submit your form.因此,无论您按下哪个按钮,它仍会提交您的表单。 If this is the problem, then adding type="button" to your previous button will fix it.如果这是问题,那么将type="button"添加到上一个按钮将解决它。

<button data-role="prevbutton" type="button" class="btn btn-secondary pull-left">Previous</button>

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

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