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 13, 2015 · 16 revisions

Removing a Validator is only available when you defined your Validations through the Angular-Validation Service, this will not work with Validations defined by the Directive (defined in the DOM will not work).

<!-- 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