重置表单后未删除验证消息
Validation messages not removed after resetting the form
我有一个html表单,我使用angular JS进行验证。在这里,提交表单后,我将调用重置方法,该方法将表单输入字段重置为默认值。
但是,当我提交并调用reset方法时,验证消息会出现在输入字段中。我使用了以下代码。我不想在提交表单后看到验证消息。
HTML
<form name="createvalidation" role="form" class="col-lg-12" novalidate>
<div class="form-group">
</div>
<div class="form-group">
<input type="text" placeholder="Challenge name" class="form-control input-sm" name="name" ng-model="challenge.challengename" required>
<span ng-show="(createvalidation.name.$dirty || submitted) && createvalidation.name.$error.required">Name is reqiured</span>
</div>
<div class="form-group">
<textarea class="form-control input-sm" rows="2" placeholder="Write more about this challenge..." name="description" ng-model="challenge.challengedescription" required></textarea>
<span ng-show="(createvalidation.description.$dirty || submitted) && challengecreatevalidation.description.$error.required">Description is reqiured</span>
</div>
</form>
<div>
<button type="button" ng-click="createChallenge()">Create</button>
</div>
JS代码
$scope.createChallenge = function() {
//get the field and store in db
$scope.resetForm();
}
$scope.master = {};
$scope.resetForm = function() {
$scope.challenge = angular.copy($scope.master);
$scope.createvalidation.$setPristine();
}
$scope.createChallenge = function() {
//get the field and store in db
$scope.resetForm();
}
$scope.master = {};
$scope.resetForm = function() {
$scope.submitted = false; //Try adding this
$scope.challenge = angular.copy($scope.master);
$scope.createvalidation.$setPristine();
}
您似乎正在从的resetForm函数中复制表单的原始状态。这意味着当调用resetForm时,它将只具有表单的版本。相反,也许您应该在表单设置好并处于原始状态时进行复制。
相关文章:
- 正在删除node.js中已验证的网站
- 从所有元素中删除HTML5验证
- preventDefault而不删除html5验证
- 在验证之前从输入值中删除文本并提交
- 如何从Knockout validation中的可观察项中删除验证规则[extenders]
- 如何从HTML5输入中删除验证错误
- AngularJS摘要周期错误,ngmodel在自定义验证时被删除
- 重置表单后未删除验证消息
- JS如何捕获基于键入然后删除的字符的字段验证逻辑
- jquery验证插件-错误删除
- 在$invalid上添加验证指令并从文本框中删除数据的指令
- 如何从jQuery验证插件函数中删除AJAX
- JQuery 验证 - 在表单中添加/删除错误 css 类
- ParlseyJS-从禁用的字段中删除验证
- Javascript删除验证是否“;好的”;或“;取消”;
- 调用event.preventDefault()后将删除验证
- 我想从网页中自动删除验证码
- 删除验证在加载数据时停止计数错误
- 如何从jQuery脚本中删除验证
- 如何从理想表单jQuery中删除验证规则