Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.

Remove Validator from Element

Ghislain B. edited this page May 18, 2015 · 16 revisions

Removing a Validator can work for both the Directive and the Service but in all situation you need to call it through the controller and for that matter you still need to use the validationService()

<!-- Add a remove button in your html -->
<span class="text-right">
    <button ng-click="removeInputValidator('input2');">
        Remove Input2 Validator
    </button>
</span>

and then in Javascript, call the removeValidator() function by passing your Form object and input name

// you need reference to your previous Service object variable
var myValidation = new validationService();

// you can also remove a Validator with an ngClick or whichever way you prefer by calling .removeValidator()
  $scope.removeInputValidator = function ( elmName ) {
    // 1st argument is the object holding our $validationSummary `$scope.yourFormName`
    //   If your form does not have a name attribute, your only choice is to use `$scope` as argument
    // 2nd argument, remove a single element (string)
    //    OR you can also remove multiple elements through an array type .removeValidator($scope.form1, ['input2','input3'])
    myValidation.removeValidator($scope.form1, elmName);
  };
Clone this wiki locally