card icon indicating copy to clipboard operation
card copied to clipboard

Add plugin for AngularJS

Open titxoo opened this issue 11 years ago • 7 comments

Create a card form in AngularJs =D

titxoo avatar Feb 19 '15 15:02 titxoo

I did mine like this:

angular.module('app.Components.CreditCard', [])

.directive('creditCardForm', creditCardFormDirective)
.directive('creditCardContainer', creditCardContainerDirective);

function creditCardFormDirective () {
    return {
        restrict: 'A',
        scope: true,
        controller: function () {
            var ctrl = this;

            ctrl.fields = {};

            ctrl.setField = function (name, element) {
                ctrl.fields[name] = element;
            }
        },
        link: function (scope, element, attrs, ctrl) {
            // TODO check for ctrl.fields presence
            var card = new Card({
                form: element[0],
                container: ctrl.fields.container[0],
                formSelectors: {
                        numberInput: '[credit-card-number]',
                        expiryInput: '[credit-card-expiry]',
                        cvcInput: '[credit-card-cvc]',
                        nameInput: '[credit-card-name]',
                },
                debug: true
            });
        }
    };
}

function creditCardContainerDirective () {
    return {
        restrict: 'EA',
        require: '^creditCardForm',
        link: function (scope, element, attrs, ccForm) {
            ccForm.setField('container', element);
        }
    }
}

thenikso avatar Mar 12 '15 11:03 thenikso

How would you use this directive?

adammahmood avatar Mar 12 '15 18:03 adammahmood

If one of y'all wants to turn this into a plugin or a wiki document, I'd be much obliged :)

jessepollak avatar Mar 15 '15 23:03 jessepollak

I use it (something) like this:

<div credit-card-form>
  <input type="text" credit-card-number>
  <input type="text" credit-card-name>
  <input type="text" credit-card-expiry>
  <input type="text" credit-card-cvc>
  <div credit-card-container></div>
</div>

thenikso avatar Mar 16 '15 11:03 thenikso

Thanks @thenikso, is working like a charm!

luisfontes avatar Apr 27 '15 14:04 luisfontes

I'm closing this for now. If someone wants to contribute an Angular plugin, I would love to accept a PR. Thanks for all your time and thought.

jessepollak avatar Jul 18 '15 20:07 jessepollak

Thanks @thenikso that worked like a charm. I tried the plugin recommended in the readme, but it was very buggy. Your method was very straight forward and I have no issues with it.

pradt avatar Oct 10 '16 04:10 pradt