- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
您好,我正在尝试将验证放入我的表单中。
更新代码
$(document).ready(function () {
$('.registration-form fieldset:first-child').fadeIn('slow');
$('.registration-form input[type="text"]').on('focus', function () {
$(this).removeClass('input-error');
});
// next step
$('.registration-form .btn-next').on('click', function () {
var parent_fieldset = $(this).parents('fieldset');
var next_step = true;
parent_fieldset.find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
$(this).addClass('input-error');
next_step = false;
} else {
$(this).removeClass('input-error');
}
});
if (next_step) {
parent_fieldset.fadeOut(400, function () {
$(this).next().fadeIn();
});
}
});
// previous step
$('.registration-form .btn-previous').on('click', function () {
$(this).parents('fieldset').fadeOut(400, function () {
$(this).prev().fadeIn();
});
});
// submit
$('.registration-form').on('submit', function (e) {
$(this).find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
e.preventDefault();
$(this).addClass('input-error');
} else {
$(this).removeClass('input-error');
}
});
});
});
</script>
.input-error {
color:yellow;
background-color:red;
}
/*style.css**/
/***** Top content *****/
.form-box {
padding-top: 0px;
font-family: Century, Tahoma, Arial, Verdana, Georgia;
}
.form-top {
overflow: hidden;
padding: 0 25px 15px 25px;
background: #008ade;
-moz-border-radius: 4px 4px 0 0;
-webkit-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
text-align: left;
color: #fff;
transition: opacity .3s ease-in-out;
}
.form-top h3 {
color: #fff;
}
.form-bottom {
padding: 25px 25px 30px 25px;
background: #c3dde8;
-moz-border-radius: 0 0 4px 4px;
-webkit-border-radius: 0 0 4px 4px;
border-radius: 0 0 4px 4px;
text-align: left;
transition: all .4s ease-in-out;
}
.form-bottom:hover {
-webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
form .form-bottom button.btn {
min-width: 105px;
}
form.registration-form fieldset {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<section>
<h1 class="pagetitle"><span> <i class="material-icons md-36">card_travel</i> Create Distributor</span></h1>
</section>
<div class="assessment-container container">
<div class="row">
<div class="col-md-6 form-box">
<?php
$attributes = array('class' => 'registration-form');
echo form_open('' ,$attributes); ?>
<fieldset class="registration-form">
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="material-icons md-36">account_balance</i> </span>Organization Information</h3>
</div>
</div>
<div class="form-bottom">
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Organization Name</label>
<input type="text" name="" class= "form-control" required title="This Field is Required">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Pincode</label>
<input type="text" name="" required class= "form-control">
</div>
</div>
<div class="form-group label-floating"">
<label for="i5" class="control-label">Address 1</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group" style="margin-bottom:3px;">
<div class="row">
<div class="form-group col-md-5 label-floating">
<label for="i5" class="control-label">City</label>
<input type="text" name="" class= "form-control">
<span class="help-block">City Organization</span>
</div>
<div class="form-group col-md-5 label-floating">
<label for="i5" class="control-label">State</label>
<input type="text" name="" class= "form-control">
<span class="help-block">Insert a State</span>
</div>
</div>
</div>
<div class="form-group label-floating"">
<label for="i5" class="control-label">Country</label>
<input type="text" name="" class= "form-control">
<span class="help-block">Insert a State</span>
</div>
<button type="button" class="btn btn-next" style="margin-top: 20px;">Next</button>
</div>
</fieldset>
<!--END OF ORGANIZATION INFORMATION -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="material-icons md-36">account_box</i></span>Sales & Technical Contact</h3>
</div>
</div>
<div class="form-bottom">
<h4>Sales Contact</h4>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">First Name</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Last Name</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Email</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Phone</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<h4>Technical Contact</h4>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">First Name</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Last Name</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Email </label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Phone</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<button type="button" class="btn btn-previous" style="margin-top: 20px;">Previous</button>
<button type="button" class="btn btn-next" style="margin-top: 20px;">Next</button>
</div>
</fieldset>
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="material-icons md-36">https</i></span>Distributor Information</h3>
</div>
</div>
<div class="form-bottom">
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Distributor Username</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Distributor Password</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<h4>Number of License for products</h4>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">MLC</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">FMS</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">UMC</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">PTT</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="submit" class="btn btn-raised btn-info">Submit</button>
</div>
</fieldset>
<?php echo form_close();?>
</div>
</div>
</div>
现在这是多级表单。如果必填字段上的值保留为空,我想添加错误类,例如组织名称是必填字段。
现在我想在按下下一个按钮时显示错误类。我的代码有什么问题?
最佳答案
您需要添加class="registration-form"
到您的表单或包含下一个按钮的某个元素,就像我通过添加到 <fieldset class="registration-form">
所做的那样
我还添加了 css 以使输入在出现错误时具有红色背景,请检查下面的输出:
$(document).ready(function () {
$('.registration-form fieldset:first-child').fadeIn('slow');
$('.registration-form input[type="text"]').on('focus', function () {
$(this).removeClass('input-error');
});
// next step
$('.registration-form .btn-next').on('click', function () {
var parent_fieldset = $(this).parents('fieldset');
var next_step = true;
parent_fieldset.find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
$(this).addClass('input-error');
next_step = false;
} else {
$(this).removeClass('input-error');
}
});
if (next_step) {
parent_fieldset.fadeOut(400, function () {
$(this).next().fadeIn();
});
}
});
// previous step
$('.registration-form .btn-previous').on('click', function () {
$(this).parents('fieldset').fadeOut(400, function () {
$(this).prev().fadeIn();
});
});
// submit
$('.registration-form').on('submit', function (e) {
$(this).find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
e.preventDefault();
$(this).addClass('input-error');
} else {
$(this).removeClass('input-error');
}
});
});
});
.input-error {
color:yellow;
background-color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset class="registration-form">
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="material-icons md-36">account_balance</i> </span>Organization Information</h3>
</div>
</div>
<div class="form-bottom">
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Organization Name</label>
<input type="text" name="" class= "form-control" required title="This Field is Required">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Pincode</label>
<input type="text" name="" required class= "form-control">
</div>
</div>
<div class="form-group label-floating"">
<label for="i5" class="control-label">Address 1</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group" style="margin-bottom:3px;">
<div class="row">
<div class="form-group col-md-5 label-floating">
<label for="i5" class="control-label">City</label>
<input type="text" name="" class= "form-control">
<span class="help-block">City Organization</span>
</div>
<div class="form-group col-md-5 label-floating">
<label for="i5" class="control-label">State</label>
<input type="text" name="" class= "form-control">
<span class="help-block">Insert a State</span>
</div>
</div>
</div>
<div class="form-group label-floating"">
<label for="i5" class="control-label">Country</label>
<input type="text" name="" class= "form-control">
<span class="help-block">Insert a State</span>
</div>
<button type="button" class="btn btn-next" style="margin-top: 20px;">Next</button>
</div>
</fieldset>
问题进展:
$(document).ready(function () {
$('fieldset:first-child').fadeIn('slow');
$('input[type="text"]').on('focus', function () {
$(this).removeClass('input-error');
});
// next step
$('.btn-next').on('click', function () {
var parent_fieldset = $(this).parents('fieldset');
var next_step = true;
parent_fieldset.find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
$(this).addClass('input-error');
next_step = false;
} else {
$(this).removeClass('input-error');
}
});
if (next_step) {
parent_fieldset.fadeOut(400, function () {
$(this).next().fadeIn();
});
}
});
// previous step
$('.btn-previous').on('click', function () {
$(this).parents('fieldset').fadeOut(400, function () {
$(this).prev().fadeIn();
});
});
// submit
$('button[type="submit"]').on('click', function (e) {
$(this).parents('fieldset').find('input[type="text"],input[type="email"]').each(function () {
if ($(this).val() == "") {
e.preventDefault();
$(this).addClass('input-error');
} else {
$(this).removeClass('input-error');
}
});
});
});
.input-error {
color:yellow;
background-color:red;
}
/*style.css**/
/***** Top content *****/
.form-box {
padding-top: 0px;
font-family: Century, Tahoma, Arial, Verdana, Georgia;
}
.form-top {
overflow: hidden;
padding: 0 25px 15px 25px;
background: #008ade;
-moz-border-radius: 4px 4px 0 0;
-webkit-border-radius: 4px 4px 0 0;
border-radius: 4px 4px 0 0;
text-align: left;
color: #fff;
transition: opacity .3s ease-in-out;
}
.form-top h3 {
color: #fff;
}
.form-bottom {
padding: 25px 25px 30px 25px;
background: #c3dde8;
-moz-border-radius: 0 0 4px 4px;
-webkit-border-radius: 0 0 4px 4px;
border-radius: 0 0 4px 4px;
text-align: left;
transition: all .4s ease-in-out;
}
.form-bottom:hover {
-webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
form .form-bottom button.btn {
min-width: 105px;
}
form.registration-form fieldset {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<section>
<h1 class="pagetitle"><span> <i class="material-icons md-36">card_travel</i> Create Distributor</span></h1>
</section>
<div class="assessment-container container">
<div class="row">
<div class="col-md-6 form-box">
<?php
$attributes = array('class' => 'registration-form');
echo form_open('' ,$attributes); ?>
<fieldset class="registration-form">
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="material-icons md-36">account_balance</i> </span>Organization Information</h3>
</div>
</div>
<div class="form-bottom">
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Organization Name</label>
<input type="text" name="" class= "form-control" required title="This Field is Required">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Pincode</label>
<input type="text" name="" required class= "form-control">
</div>
</div>
<div class="form-group label-floating"">
<label for="i5" class="control-label">Address 1</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group" style="margin-bottom:3px;">
<div class="row">
<div class="form-group col-md-5 label-floating">
<label for="i5" class="control-label">City</label>
<input type="text" name="" class= "form-control">
<span class="help-block">City Organization</span>
</div>
<div class="form-group col-md-5 label-floating">
<label for="i5" class="control-label">State</label>
<input type="text" name="" class= "form-control">
<span class="help-block">Insert a State</span>
</div>
</div>
</div>
<div class="form-group label-floating"">
<label for="i5" class="control-label">Country</label>
<input type="text" name="" class= "form-control">
<span class="help-block">Insert a State</span>
</div>
<button type="button" class="btn btn-next" style="margin-top: 20px;">Next</button>
</div>
</fieldset>
<!--END OF ORGANIZATION INFORMATION -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="material-icons md-36">account_box</i></span>Sales & Technical Contact</h3>
</div>
</div>
<div class="form-bottom">
<h4>Sales Contact</h4>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">First Name</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Last Name</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Email</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Phone</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<h4>Technical Contact</h4>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">First Name</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Last Name</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Email </label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Phone</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<button type="button" class="btn btn-previous" style="margin-top: 20px;">Previous</button>
<button type="button" class="btn btn-next" style="margin-top: 20px;">Next</button>
</div>
</fieldset>
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h3><span><i class="material-icons md-36">https</i></span>Distributor Information</h3>
</div>
</div>
<div class="form-bottom">
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Distributor Username</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">Distributor Password</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<h4>Number of License for products</h4>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">MLC</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">FMS</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">UMC</label>
<input type="text" name="" class= "form-control">
</div>
<div class="form-group col-md-6 label-floating">
<label for="i5" class="control-label">PTT</label>
<input type="text" name="" class= "form-control">
</div>
</div>
<button type="button" class="btn btn-previous">Previous</button>
<button type="submit" class="btn btn-raised btn-info">Submit</button>
</div>
</fieldset>
<?php echo form_close();?>
</div>
</div>
</div>
关于javascript - 如果输入为空,则以逐步形式放置错误类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42131299/
这是一个新手理论问题 - 我刚刚开始使用 Python 并研究 Django 和 orm。问题:如果我开发我的对象并通过额外的开发修改基础对象结构、继承等 - Django 的 ORM 解决方案会自动
我正在使用带有服务器端处理器的 JavaScript 表单,并且我希望能够让表单根据下拉列表转到不同的电子邮件。我已经根据其他表格尽了最大努力,但似乎无法通过电子邮件。我已在电子邮件地址的选项标签下添
一个简单的问题:给定定义,(来自 Haskell SOE) do x — el; el\ ...; en => el »= \x — do e2\ ...; en 和: do let d
我是 Angular 5 的新手。我目前正在研究 Angular Reactive 表单。我有一个下面的 JSON 结构,我需要在从 FORM 获取值后发回 REST API。 JSON 结构: {
我是 Angular 5 的新手。我目前正在研究 Angular Reactive 表单。我有一个下面的 JSON 结构,我需要在从 FORM 获取值后发回 REST API。 JSON 结构: {
我有一个类型(称之为 A),我想创建一个 A -> A、A -> A -> A、A -> A -> A -> ... 等类型的函数的类型类.这不起作用: {-# LANGUAGE FlexibleIn
我正在使用 java 线程同时管理多个 (3) 程序。1 用于 Java swing 表单(绘制 UI 以进行输入),1 用于在系统托盘上设置图标(从 UI 获取输入后立即启动),1 用于处理输入并将
在当前的元素中,我在表单中遇到了一个问题。表单中标签的字体大小可能大于默认值。如果我把它举起来,那么右边的输入必须垂直居中。 我查看了 Bootstrap 和 Foundation,但都没有解决这个问
为了好玩,我使用了一段从 friend 那里得到的代码,并尝试创建一个包含用户名和密码的登录字段,但我很难获得单词旁边的字段。 username 这个词和你输入的框之间有很大的差距。密码也是如此。 这
我的表单中有一个嵌套的控制组,我想访问它们的表单状态值(如原始和有效)以动态显示验证错误。 是这样动态构建的 controlMap['password'] = this.password; contr
发送后我试图重置我的表单,但只有值设置为空。 component.html {{note.value?.length || 0}}/10
我正在尝试自定义 Stripe 结帐表单,但我不知道如何添加输入。我想添加“电话号码”和“姓名”以创建费用和客户。你知道我该怎么做吗? 这是我应该自定义的代码。 最佳答案 您将无法使用
所以我有这个需求,我想以表格的形式提交一个由五个记录组成的表单。这就是它的样子表: 这是对应的代码: Section Q.No Question
我有一个使用 react 形式和输入文本的情况。 我需要: 当用户输入时,根据输入的内容建议一个列表(我使用的是 ngx bootstrap typeahead); 仅当用户失去输入焦点时才验证输入字
我希望重构我的 Angular 项目中的大量组件,以具有强类型的 FormGroups、FormArrays 和 FormControls。 我只是在寻找一种实现强类型 react 形式的好方法。任何
我有事件表格: 'horizontal', 'fieldConfig' => [ 'template' => "{input}\n{hint}\n{error}",
是否有关于如何实现多选和响应式表单的示例? 我正在尝试在 multiselect-dropdown 上设置所选项目(从数据库中检索),它会更新显示的项目( View ),但会引发以下错误: core.
我想在表单中添加按钮以动态添加输入。但是我发现,如果我在表单中添加了一个仅记录到控制台的按钮(并且当我尝试添加输入时),它将记录日志,然后表单中断。我的Electron应用程序的前端窗口崩溃(不退出但
我有一个这样的表格 此表单位于指令内: angular.module('crowdcoreApp').directive('investorForm',function(){
我在 angularjs Controller 中调用的 $mdDialog 中有一个表单,如下所示: actions-controller.js function callForm() {
我是一名优秀的程序员,十分优秀!