我有一个引导验证器的问题,我有一个 angularjs 项目,我在指令的模式中有一个表单。所以,我想当模式隐藏时,将表单重置为验证器重置。但是当我使用:
$('#StandardForm').bootstrapValidator('resetForm', true);
什么都没有发生,当我回想起我的表单模式时,验证器总是在这里。(输入是绿色(好)或红色(不好))。
看我的指令:
angular.module('app.administration').directive('wcStandardForm',['servicesHTTP', function(servicesHTTP)
{
return {
restrict: 'E',
scope: {
standard: '=',
method: '&'
},
replace: true,
templateUrl: 'app/administration/directives/standard/wc-standard-form.tpl.html',
link: function(scope, form)
{
form.bootstrapValidator({
framework: 'bootstrap',
excluded: ':disabled',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
name: {
validators: {
notEmpty: {
message: 'le nom est nécessaire.'
},
stringLength: {
max: 31,
message: 'Le nom ne doit pas dépasser 31 caractères.'
}
}
}
}
});
},
controller: function($scope)
{
/**
* Vide le moduleForm
*/
$scope.clearStandardForm = function()
{
//$scope.standard = {};
$('#StandardForm').bootstrapValidator('resetForm', true);
};
/**
* Valide le module et envoi la requete http
*/
$scope.validateStandardForm = function()
{
...
$scope.clearStandardForm();
};
}
};
}]);
这里是模板:
<div class="modal fade" id="standardFormModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true" ng-click="clearStandardForm()">×</span>
<span ng-click="clearStandardForm()" class="sr-only">Close</span>
</button>
<h4 class="modal-title">Assigner fonctions</h4>
</div>
<div class="modal-body">
<form id="StandardForm" method="post" class="ng-pristine ng-valid bv-form" novalidate="novalidate">
<button type="submit" class="bv-hidden-submit" style="display: none; width: 0px; height: 0px;"></button>
<div class="form-group">
<label class="control-label">Nom</label>
<input type="text" class="form-control" name="name" ng-model="standard.standard_name">
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-12">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="clearStandardForm()">Close</button>
<button type="submit" class="btn btn-primary"data-dismiss="modal" ng-click="validateStandardForm()"><i class="fa fa-save"></i> Sauvegarder</button>
</div>
</div>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
我试图在模态$('#StandardForm').bootstrapValidator('resetForm', true);
的事件show.bs.modal
等hidden.bs.modal
上做同样的事情。
所以如果你有想法,我会接受的:)