使用Bootstrap在表单中标记错误

卢西亚诺

我已经开始使用Bootstrap来实现漂亮的页面设计而无需借助GWT(后端是用Java制作的)

对于我的登录屏幕,我复制了此示例现在,我想标记一个错误,例如,用户名留空。所以我想知道Bootstrap框架中的程序是什么。或者,如果有示例显示有错误的表格。

我不确定该想法是在红色输入元素内显示错误消息,还是在输入元素下方显示错误消息,或者是否弹出窗口?

乔施林克特

(已通过Bootstrap v4,v3和v3的示例进行了更新)

过去几个主要版本的Bootstrap的带有验证类的表单示例。

Bootstrap v4

在Codepen上查看实时版本

bootstrap v4表单验证

<div class="container">
  <form>
    <div class="form-group row">
      <label for="inputEmail" class="col-sm-2 col-form-label text-success">Email</label>
      <div class="col-sm-7">
        <input type="email" class="form-control is-valid" id="inputEmail" placeholder="Email">
      </div>
    </div>

    <div class="form-group row">
      <label for="inputPassword" class="col-sm-2 col-form-label text-danger">Password</label>
      <div class="col-sm-7">
        <input type="password" class="form-control is-invalid" id="inputPassword" placeholder="Password">
      </div>
      <div class="col-sm-3">
        <small id="passwordHelp" class="text-danger">
          Must be 8-20 characters long.
        </small>      
      </div>
    </div>
  </form>
</div>

Bootstrap v3

在Codepen上查看实时版本

bootstrap v3表单验证

<form role="form">
  <div class="form-group has-warning">
    <label class="control-label" for="inputWarning">Input with warning</label>
    <input type="text" class="form-control" id="inputWarning">
    <span class="help-block">Something may have gone wrong</span>
  </div>
  <div class="form-group has-error">
    <label class="control-label" for="inputError">Input with error</label>
    <input type="text" class="form-control" id="inputError">
    <span class="help-block">Please correct the error</span>
  </div>
  <div class="form-group has-info">
    <label class="control-label" for="inputError">Input with info</label>
    <input type="text" class="form-control" id="inputError">
    <span class="help-block">Username is taken</span>
  </div>
  <div class="form-group has-success">
    <label class="control-label" for="inputSuccess">Input with success</label>
    <input type="text" class="form-control" id="inputSuccess" />
    <span class="help-block">Woohoo!</span>
  </div>
</form>

Bootstrap v2

在jsfiddle上查看实时版本

bootstrap v2表单验证

.error.success.warning.info类被附加到.control-group这是v2中的标准Bootstrap标记和样式。只要遵循该步骤,您就可以保持良好状态。当然,如果愿意,您可以按照自己的样式添加弹出窗口或“嵌入式Flash”,但是如果您遵循Bootstrap约定并将这些验证类挂在其上.control-group,它将保持一致且易于管理(至少因为将会继续受益于Bootstrap文档和示例)

  <form class="form-horizontal">
    <div class="control-group warning">
      <label class="control-label" for="inputWarning">Input with warning</label>
      <div class="controls">
        <input type="text" id="inputWarning">
        <span class="help-inline">Something may have gone wrong</span>
      </div>
    </div>
    <div class="control-group error">
      <label class="control-label" for="inputError">Input with error</label>
      <div class="controls">
        <input type="text" id="inputError">
        <span class="help-inline">Please correct the error</span>
      </div>
    </div>
    <div class="control-group info">
      <label class="control-label" for="inputInfo">Input with info</label>
      <div class="controls">
        <input type="text" id="inputInfo">
        <span class="help-inline">Username is taken</span>
      </div>
    </div>
    <div class="control-group success">
      <label class="control-label" for="inputSuccess">Input with success</label>
      <div class="controls">
        <input type="text" id="inputSuccess">
        <span class="help-inline">Woohoo!</span>
      </div>
    </div>
  </form>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Checked Exception需要在编译时使用try,catch和finally关键字进行处理,否则编译器将标记错误

Media CSS标记错误| 预期的规则或选择器

找不到web.xml中的TagLib标记错误

Tomcat可以理解amq:broker,但是Eclipse会在模式中标记错误

属性[path]对于标记错误是必需的,但是指定了path

如何正确标记错误以符合golang

说明Maven JavaDoc插件为空<p>标记错误

奇怪的“样式表”标记错误

Search Console的Sitemap xml标记错误:无效的XML标记<sitemap>

联系表格未标记错误PHP

使用:h时标记错误

表单中的SwiftUI Picker不显示CoreData的选中标记

Webforms元标记错误?

图例中标记的类型错误

修复后,jQuery验证程序仍会标记错误

尝试从URL读取标记文件时出现斯坦福POS标记错误

web.config中的位置标记错误

在PHP上使用post在多页表单上选中(选中标记)相同的复选框

Google PubSub getMessageID = null是否因为标记错误?

标记错误:document.getElementById(...) 为空或不是对象

Typescript lint 标记错误

如何修复 Google 地图中的重叠标记错误

在 Cucumber Step Defination 中使用 System.setProperty 时出现多个标记错误

leetcode 问题,适用于测试码,但标记错误

表单标记错误:无值 > 带有名称的表单控件的访问器

keytool 错误:java.io.IOException:DER 输入,整数标记错误

Xcode 13 Beta - 枚举案例@available 标记错误

JavadocMethod:实际存在时预期的@param 标记错误

S3 标记错误 - 您提供的 TagValue 无效