所有按钮触发表单验证语义ui [英] All buttons trigger form validation semantic ui

查看:56
本文介绍了所有按钮触发表单验证语义ui的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的语义UI表单(< div class ="ui表单"> )中,似乎每个按钮都会触发表单验证,即使它不是提交按钮也是如此.

In my semantic UI form (<div class="ui form">) it appears every button triggers the form validation, even if it is not a submit button.

以下两种不同的按钮:

<button class="ui blue right labeled icon primary submit button">
  <i class="right arrow icon"></i>
  Submit
</button>

<button class="ui blue button">  
  Something Else
</button>

这两个

都在semnatic UI表单元素内.都触发我的验证规则(标准设置规则):

both of these are inside the semnatic UI form element. both trigger my validation rules (standard setup rules) :

$('.ui.form')
  .form({
    fields: {
      example:: {
        identifier: 'example',
        rules: [
          {
            type   : 'empty',
            prompt : 'Please enter at least one thing'
          }
        ]
      }   
    }
  }
  )
;

我只能在网上找到的解决方案"是在创建这样的按钮:

Only "Solution" I could find online was creating a button like this:

<input type="button"  class="ui blue button">
Test
</input>

但这不会将文本(测试")放在按钮内,也无法使按钮的大小与其他按钮相同.

but this doesn't put the text ("test") inside the button, also couldnt get the size of the button to be same as other ones.

有没有一种方法可以使其不触发我的验证?为何不提交按钮的原因颇为困惑.

Is there a way to get it to not trigger my validation? Pretty stumped on why a non submit button is doing it.

推荐答案

只需定义按钮的类型.默认类型为提交:

Simply define the type of the button. Default type is submit:

<Button type="button" />

参考: https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/button#Attributes

这篇关于所有按钮触发表单验证语义ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆