Reputation: 3841
I am trying to implement custom validation with angular js
.
The following code runs perfectly on FireFox
however IE 11
throws an error
Expected ':'
for the line return scope.valFunc({value});
Any ideas how to remedy that for IE
?
Thanks.
Directive:
crudApp.directive('customValidationFunction', function() {
return {
restrict: 'A',
require: 'ngModel',
scope: {
valFunc: '&customValidationFunction'
},
link: function(scope, element, attrs, controller) {
const normalizedFunc = function(modelValue, viewValue) {
const $value = modelValue || viewValue;
return scope.valFunc({$value});
};
controller.$validators.customValidationFunction = normalizedFunc;
}
};
});
Validation Function:
//custom validation test
$scope.custValidationFunc = function($value) {
if (!$value) {
return true;
}
const lowVal = String($value).toLowerCase();
return lowVal.indexOf("arnold") === -1 && lowVal.indexOf("sylvester") === -1;
}
Html:
<input type="text" class="form-control" id="i_position" name="i_position" aria-describedby="i_position_help" placeholder="Enter your Position" ng-model="position" custom-validation-function="custValidationFunc($value)">
Upvotes: 0
Views: 26
Reputation: 430
scope.valFunc({value})
is ES6 syntax & IE doesn't support it. You need to integrate Babel or simple change to scope.valFunc({value: value})
Upvotes: 1