-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds custom directive for CVV validation.
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import angular from 'angular' | ||
import * as cruPayments from '@cruglobal/cru-payments/dist/cru-payments' | ||
|
||
const directiveName = 'creditCardCvv' | ||
|
||
const creditCardCvv = /* @ngInject */ function () { | ||
const directiveDefinitionObject = { | ||
restrict: 'A', | ||
require: ['^ngModel', '^form'], | ||
link: function (scope, element, attributes, controllers) { | ||
const ngModel = controllers[0] | ||
const formController = controllers[1] | ||
const valueModel = formController[attributes.creditCardCvv] | ||
|
||
scope.$watch(() => valueModel.$viewValue, function () { | ||
ngModel.$validate() | ||
}) | ||
|
||
ngModel.$validators.creditCardCvv = function (modelValue) { | ||
console.log(modelValue) | ||
return (cruPayments.creditCard.cvv.validate.minLength(modelValue)) && (cruPayments.creditCard.cvv.validate.maxLength(modelValue)) | ||
} | ||
} | ||
} | ||
return directiveDefinitionObject | ||
} | ||
|
||
export default angular | ||
.module(directiveName, []) | ||
.directive(directiveName, creditCardCvv) |