- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我曾经使用 Bootstrap 3 实现 Angular 2/4 应用程序,并使用了 Reactive Forms 方法。我有一个字段验证,其中输入字段的边框变为红色,并且在该字段下方以红色字体显示一条错误消息。
看起来像这样:
<div class="form-group row"
[ngClass]="{'has-error': (sourcesForm.get('sourceName').touched ||
sourcesForm.get('sourceName').dirty) &&
!sourcesForm.get('sourceName').valid }">
<label class="col-md-2 col-form-label"
for="sourceNameId">Source Name</label>
<div class="col-md-8">
<input class="form-control"
id="sourceNameId"
type="text"
placeholder="Source Name (required)"
formControlName="sourceName" />
<span class="help-block" *ngIf="(sourcesForm.get('sourceName').touched ||
sourcesForm.get('sourceName').dirty) &&
sourcesForm.get('sourceName').errors">
<span *ngIf="sourcesForm.get('sourceName').errors.required">
Please enter the Source Name.
</span>
<span *ngIf="sourcesForm.get('sourceName').errors.minlength">
The Source Name must be longer than 3 characters.
</span>
<span *ngIf="sourcesForm.get('sourceName').errors.maxlength">
The Source Name is too long.
</span>
</span>
</div>
</div>
现在我必须使用 Bootstrap 4,错误消息或输入字段都不会变红。我如何意识到这一点?我试图将父 span-block 的类更改为“form-text”,但没有成功。
最佳答案
对于 Bootstrap v4 的测试版,您可以查看 Form validation docs .在那里您可以阅读有关新方法的信息,所有现代浏览器都支持使用有效/无效 css 类进行表单验证的 HTML5 方式。 Bootstrap 使用 .was-validated
和 .invalid-feedback
类来实现您想要实现的目标(参见代码片段)。
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<form class="container" id="needs-validation" novalidate>
<label for="validationCustom02">Last name</label>
<input type="text" class="form-control" id="validationCustom02" placeholder="Last name" value="Otto" required>
<label for="validationCustom03">City</label>
<input type="text" class="form-control" id="validationCustom03" placeholder="City" required>
<div class="invalid-feedback">
Please provide a valid city.
</div>
<button class="btn btn-primary" type="submit">Submit form</button>
</form>
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
"use strict";
window.addEventListener("load", function() {
var form = document.getElementById("needs-validation");
form.addEventListener("submit", function(event) {
if (form.checkValidity() == false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add("was-validated");
}, false);
}, false);
}());
</script>
如果你想要更类似于 Bootstrap 3 的东西,你可以使用他们所谓的服务器端验证,正如它所写的那样:
As a fallback, .is-invalid and .is-valid classes may be used instead of the pseudo-classes for server side validation. They do not require a .was-validated parent class.
Bootstrap V4 alpha 版的先前答案(如果您必须使用它)。在 Bootstrap V4 Form Validation Docs有以下例子:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group has-danger">
<label class="form-control-label" for="inputDanger1">Input with danger</label>
<input type="text" class="form-control form-control-danger" id="inputDanger1">
<div class="form-control-feedback">Sorry, that username's taken. Try another?</div>
<small class="form-text text-muted">Example help text that remains unchanged.</small>
</div>
所以我认为您只需要将 has-error
类更改为 has-danger
关于html - 输入字段或帮助文本在字段无效时不会变为红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45975162/
当运行这段代码时,它会以默认大小打开窗口: View [ text "window open with default size" ] 如果 a 明确给出一个大小,它将打开一个具有该大小的窗口
我创建了一个 DataGridView 并添加了一个 DataGridViewImageColumn(使用设计器)。 DataGridView 具有“AllowUserToAddRows = true
如何实现红色数字指示器(例如电子邮件计数通知)? 最佳答案 您正在寻找的是 applicationIconBadgeNumber 属性,它是 UIApplication 的属性。 要从应用中的任何位置
我很想得到一些知道如何解释如何在红色 Node 中创建十六进制到“文本”解码器的人的意见。 我有一个 Elsys 传感器,可以生成包含温度、湿度等信息的有效载荷十六进制。 交付的有效负载是“0100d
我正在使用 node-red 程序,并且使用 OPCUA Node ,该 Node 在有效负载中返回对象数组。 我需要获取对象的一些变量,例如项目的nodeId;我尝试使用下一种格式: var new
我们开发了一个在 OS 6 及更高版本上使用 Blackberry BarcodeScanner 类解码 QR 码的应用程序。当调用条形码扫描仪屏幕时,操作系统对相机权限和应用程序的警告被隐藏,即它进
我需要 SprikeKit 方面的帮助或建议。我的应用程序/游戏通过了 Apple 审查,但后来我收到了一些关于图形的投诉(大红色 X)。我正在使用 spriteNodeWithImageNamed
有人可以看看我的 jsfiddle,看看是否可以使红色 div 在中间垂直对齐,并使红色 div 也居中。您必须使包含红色 div 的 div 具有一定高度 jsFiddle
我不希望我的子页面继承父主题的链接颜色(红色),而是我希望我的子页面上有白色链接,我应该在 html/css 中更改什么才能实现这一点? 父页面CSS a{ text-decoration:no
我想尽可能使用系统颜色。如何选择不包含在系统颜色中的颜色? 两者都是SystemColors WPF 类,SystemColors GetSysColor 的 WinForms 类和 COLOR_*
有谁知道如何以编程方式处理 Android HTC 设备红色(电源)按钮以停止我的操作。当用户在我的屏幕上时按下 REd 按钮时,我想停止运行我的一些操作。我知道对于像后退按钮这样的其他按钮,我可以使
嗨,我是图像处理方面的新手,现在我正在使用 python 处理图像以获得更多洞察力。但是,我对颜色 channel 的理解有点不满意。 在我看来,形状为 (400, 400, 3) 的 RGB 图像意
我正在遵循此处红色文档中的示例:http://static.red-lang.org/red-system-specs.html#section-14 这是我的代码: Red [] #import [
十分钟的谷歌搜索不断返回相同的答案,但在我的情况下无效。我想禁用 Aptana 为制作这些波浪线所做的一切。 我找到了几个指向 Window->Preferences->General->Editor
如何在 Red/System 中创建指向数组中第一个元素的指针? 将地址分配给指针没有问题: my-integer: 1 ptr: declare pointer! [integer!] ptr: :
我希望 webview 在按下后退按钮时显示上一页我正在使用 .canGoBack 来完成此操作,但“.canGoBack”和“.GoBack”带有红线下划线,声明 ==== “无法从静态上下文引用非
有谁知道为什么在 Xcode 项目的导航器中我的 Pods.xcodeproj 文件以红色列出?我假设这意味着 Xcode 无法找到该文件,那么我如何确保它确实存在于项目中。 谢谢! 最佳答案 在工作
Java 线程堆栈组织由以下描述 diagram in comments .所以 1 glibc guard page 似乎是由 pthread_attr_init(pthread_attr*) 设置
我在一个 Conceal 的模态 div 中有一个类似于 facebook 的按钮,当用户单击一个按钮时,模态就会出现。 不幸的是,出现的 facebook 按钮上有一个红色矩形,见下图: 我用的是I
我真的很想在 css 中创建红色的 instagram 泡泡用如图所示的圆形尖端: 除了圆头,我几乎什么都有,但我不确定我应该如何做到最好...... 这是我目前所拥有的: .notif { di
我是一名优秀的程序员,十分优秀!