Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
Merge 87233a8 into e8bc097
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSharpieOne committed Jul 26, 2018
2 parents e8bc097 + 87233a8 commit 8f4a8f5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/directive.js
Expand Up @@ -22,7 +22,8 @@
required: '=?',
onCreate: '&',
onSuccess: '&',
onExpire: '&'
onExpire: '&',
onError: '&'
},
link: function (scope, elm, attrs, ctrl) {
scope.widgetId = null;
Expand Down Expand Up @@ -54,7 +55,8 @@
tabindex: scope.tabindex || attrs.tabindex || null,
size: scope.size || attrs.size || null,
badge: scope.badge || attrs.badge || null,
'expired-callback': expired
'expired-callback': expired,
'error-callback': attrs.onError ? error : undefined

}).then(function (widgetId) {
// The widget has been created
Expand Down Expand Up @@ -96,6 +98,17 @@
scope.onExpire({ widgetId: scope.widgetId });
});
}

function error() {
var args = arguments;
$timeout(function () {
scope.response = "";
validate();

// Notify about the response availability
scope.onError({ widgetId: scope.widgetId, arguments: args });
});
}

function validate(){
if(ctrl){
Expand Down
26 changes: 26 additions & 0 deletions tests/directive_test.js
Expand Up @@ -58,6 +58,7 @@ describe('directive: vcRecaptcha', function () {
$scope.key = VALID_KEY;
$scope.onCreate = jasmine.createSpy('onCreate');
$scope.onSuccess = jasmine.createSpy('onSuccess');
$scope.onError = jasmine.createSpy('onError');
});

afterEach(function () {
Expand Down Expand Up @@ -173,6 +174,31 @@ describe('directive: vcRecaptcha', function () {
});
});

it('should call the onError callback', function () {
var element = angular.element('<form name="form">' +
'<input type="text" ng-model="something" />' +
'<div vc-recaptcha key="key" on-create="onCreate()" on-error="onError({arguments: args, widgetId: id})"/>' +
'</form>'),

_fakeCreate = function (element, config) {
config['error-callback']('something about the error');

return {
then: function (cb) {
cb();
}
};
};

spyOn(vcRecaptchaService, 'create').and.callFake(_fakeCreate);

$compile(element)($scope);
$scope.$digest();
$timeout.flush();

expect($scope.onError).toHaveBeenCalled();
});

it('the widget should be using the setted language', function () {
var element = angular.element('<form name="form">' +
'<input type="text" ng-model="something" />' +
Expand Down

0 comments on commit 8f4a8f5

Please sign in to comment.