From 3cd3fa8ad26c51273a0d66d67e69e234568d4a8b Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 11 Oct 2014 12:42:52 +0200 Subject: [PATCH] Fix browser autofill event problem with angular. Removing usage of angular databinding and use standard jquery like access to dom values. --- app/coffee/modules/auth.coffee | 19 +++++++++++-------- app/partials/views/modules/login-form.jade | 6 +++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/coffee/modules/auth.coffee b/app/coffee/modules/auth.coffee index 9f65a2d3..90713c5e 100644 --- a/app/coffee/modules/auth.coffee +++ b/app/coffee/modules/auth.coffee @@ -172,9 +172,7 @@ module.directive("tgPublicRegisterMessage", ["$tgConfig", "$tgNavUrls", PublicRe LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $events) -> link = ($scope, $el, $attrs) -> - $scope.data = {} - - onSuccessSubmit = (response) -> + onSuccess = (response) -> if $routeParams['next'] and $routeParams['next'] != $navUrls.resolve("login") nextUrl = $routeParams['next'] else @@ -183,16 +181,21 @@ LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $ $events.setupConnection() $location.path(nextUrl) - onErrorSubmit = (response) -> + onError = (response) -> $confirm.notify("light-error", "According to our Oompa Loompas, your username/email or password are incorrect.") #TODO: i18n submit = -> - form = $el.find("form").checksley() + form = new checksley.Form($el.find("form.login-form")) if not form.validate() return - promise = $auth.login($scope.data) - promise.then(onSuccessSubmit, onErrorSubmit) + data = { + "username": $el.find("form.login-form input[name=username]").val(), + "password": $el.find("form.login-form input[name=password]").val() + } + + promise = $auth.login(data) + return promise.then(onSuccess, onError) $el.on "click", "a.button-login", (event) -> event.preventDefault() @@ -227,7 +230,7 @@ RegisterDirective = ($auth, $confirm, $location, $navUrls, $config) -> onErrorSubmit = (response) -> if response.data._error_message? $confirm.notify("light-error", "According to our Oompa Loompas there was an error. #{response.data._error_message}") #TODO: i18n - + form.setErrors(response.data) submit = -> diff --git a/app/partials/views/modules/login-form.jade b/app/partials/views/modules/login-form.jade index 3dca584e..0fe86cae 100644 --- a/app/partials/views/modules/login-form.jade +++ b/app/partials/views/modules/login-form.jade @@ -1,16 +1,16 @@ div.login-form-container(tg-login) form.login-form fieldset - input(type="text", name="username", ng-model="data.username", data-required="true", + input(type="text", name="username", data-required="true", placeholder="Username or Email (case sensitive)") fieldset.login-password - input(type="password", name="password", ng-model="data.password", data-required="true", + input(type="password", name="password", data-required="true", placeholder="Password (case sensitive)") // This should be hidden when focus on pass a.forgot-pass(href="", tg-nav="forgot-password", title="Did you forgot your password?") Forgot it? fieldset - a.button.button-login.button-gray(href="", ng-click="ctrl.submit()", title="Sign in") Sign in + a.button.button-login.button-gray(href="", title="Sign in") Sign in input(type="submit", style="display:none") tg-public-register-message