【发布时间】:2013-09-10 00:03:06
【问题描述】:
我正在尝试使用 Angular.js 创建一个子表单 <div ng-form="vacancyForm">
有一种数据有很多字段
- 标题
- 可用日期
- 价格
所有人都有required 验证。
一旦我提交了该数据,我将用它做我需要的事情,但我想重置子表单,以便所有字段都不脏,并且表单在清除字段时有效,但所有字段都是无效,因为它们现在很脏,但为空,将它们标记为无效。
示例字段
<div class="control-group" ng-class="getErrorClasses(vacancyForm.headline)">
<label class="control-label" for="headline">Headline</label>
<div class="controls">
<input type="text" class="input-xlarge" id="headline" name="headline" required ng-model="new_vacancy.headline">
<span class="help-inline" ng-show="showError(vacancyForm.headline, 'required')">This field is required</span>
</div>
</div>
这里是提交时调用的函数
$scope.addVacancy = function(){
// save the submitted data
$scope.school.vacancies.push($scope.new_vacancy);
// now clear it out
$scope.new_vacancy = {};
$scope.new_vacancy.date = new Date();
// this clears out all the fields and makes them all invalid
// as they are empty. how to reset the form???
}
【问题讨论】:
标签: angularjs