Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,19 @@ angular.module('app', ['gavruk.card'])
}]);
```

#### Using multiple fields for card expiry
#### Using multiple fields

Simply use 2 input fields for the expiry, and pass either `month`, or `year` to the directive.

```js
<input placeholder="MM" type="text" name="CardExpiryMonth" card-expiry="month" data-ng-model="card.expiryMonth" />
<input placeholder="YYYY" type="text" name="CardExpiryYear" card-expiry="year" data-ng-model="card.expiryYear" />
```


Simply use 2 input fields for the name, and pass either `first`, or `last` to the directive.

```js
<input placeholder="CARD" type="text" name="CardFirstName" card-name="first" data-ng-model="card.firstName" />
<input placeholder="HOLDER" type="text" name="CardLastName" card-name="last" data-ng-model="card.lastName" />
```
16 changes: 12 additions & 4 deletions src/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ var hasRequire = window && window.angular ? false : typeof require === 'function
if (cardCtrl.cvcInput && cardCtrl.cvcInput.length > 0) {
opts.formSelectors.cvcInput = 'input[name="' + cardCtrl.cvcInput[0].name + '"]';
}
if (cardCtrl.nameInput && cardCtrl.nameInput.length > 0) {
opts.formSelectors.nameInput = 'input[name="' + cardCtrl.nameInput[0].name + '"]';

if (angular.isDefined(cardCtrl.nameInput.combined)) {
opts.formSelectors.nameInput = 'input[name="' + cardCtrl.nameInput.combined[0].name + '"]';
} else if (angular.isDefined(cardCtrl.nameInput.first) && angular.isDefined(cardCtrl.nameInput.last)) {
opts.formSelectors.nameInput = 'input[name="' + cardCtrl.nameInput.first[0].name + '"], input[name="' + cardCtrl.nameInput.last[0].name + '"]';
}

//Don't initialize card until angular has had a chance to update the DOM with any interpolated bindings
Expand Down Expand Up @@ -127,15 +130,20 @@ var hasRequire = window && window.angular ? false : typeof require === 'function
return {
restrict: 'A',
scope: {
ngModel: '='
ngModel: '=',
type: '@cardName'
},
require: [
'^card',
'ngModel'
],
link: function (scope, element, attributes, ctrls) {
var cardCtrl = ctrls[0];
cardCtrl.nameInput = element;
var nameType = scope.type || 'combined';
if (angular.isUndefined(cardCtrl.nameInput)) {
cardCtrl.nameInput = {};
}
cardCtrl.nameInput[nameType] = element;
scope.$watch('ngModel', function (newVal, oldVal) {
if (!oldVal && !newVal) {
return;
Expand Down