Reputation: 315
I'm trying to add reCaptcha to my angular form. It runs my form submit function "resetPassword" on the recaptcha callback like below which then on callback runs $scope.submitResetForm(). But when I submit the form, it loses the scope and the input field "forgot_password_dialog_username" that needs to be submitted can't be found on the page. The console gives the error right at the bottom. Any suggestions?
<input name="forgot_password_dialog_username" id="forgot_password_dialog_username" value="" class="form-control" ng-model="forgot_password_dialog_username">
<button
type="submit"
class="btn btn-primary btn-lg btn-block top-buffer30 g-recaptcha"
data-sitekey="<?php echo GOOGLE_RECAPTCHA_INVISIBLE_SITE_KEY; ?>"
data-callback="resetPassword">
Reset Password>
</button>
$scope.submitResetForm = function($scope) {
$scope.showErrors = false;
$scope.shouldShowProfileImage = false;
if ($scope.forgot_password_dialog_username.length < 3) {
LoginStateHelper.setStateForNoResetEmailOrUsername($scope);
return
}
$scope.sendingRequest = true;
$http.get(URL + '/reset/' + $scope.forgot_password_dialog_username).then(function () {
LoginStateHelper.setStateForPasswordResetResponse($scope);
});
};
$window.resetPassword = $scope.submitResetForm;
Uncaught TypeError: Cannot read property 'length' of undefined
at $scope.submitResetForm (LoginForm.js)
at br.n.Be (recaptcha__en.js)
Upvotes: 0
Views: 161
Reputation: 29
change this $scope.submitResetForm = function($scope)
by this $scope.submitResetForm = function()
you don't have to passe the $scope into the function.
Upvotes: 1