Repository: stratos
Updated Branches:
  refs/heads/master 082afd3ad -> 3ca56bb50


Fixing login page validation error message being cleared in enter key press


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/3ca56bb5
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/3ca56bb5
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/3ca56bb5

Branch: refs/heads/master
Commit: 3ca56bb50e6487343551cf2eb2dd6602d13f27d8
Parents: 082afd3
Author: Imesh Gunaratne <[email protected]>
Authored: Mon May 18 19:44:28 2015 +0530
Committer: Imesh Gunaratne <[email protected]>
Committed: Mon May 18 19:44:39 2015 +0530

----------------------------------------------------------------------
 .../console/themes/theme0/js/login/login.js     | 52 +++++++++++---------
 1 file changed, 28 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/3ca56bb5/components/org.apache.stratos.manager.console/console/themes/theme0/js/login/login.js
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager.console/console/themes/theme0/js/login/login.js
 
b/components/org.apache.stratos.manager.console/console/themes/theme0/js/login/login.js
index e039e8b..06df12c 100644
--- 
a/components/org.apache.stratos.manager.console/console/themes/theme0/js/login/login.js
+++ 
b/components/org.apache.stratos.manager.console/console/themes/theme0/js/login/login.js
@@ -19,41 +19,41 @@
  *
  */
 
-$(document).ready(function(){
+$(document).ready(function () {
     $('#username').focus(); //set user cursor into username
     var username = $('#username'), // Get the username field
         password = $('#password'), // Get the password field
         form_error = $('.form-error');
 
     //handle form valiadation
-    var isValidForm = function(){
-        if(username.val() == "" || password.val() == ""){
+    var isValidForm = function () {
+        if (username.val() == "" || password.val() == "") {
             var error = "Enter your username";
-            if(username.val() == ""){
+            if (username.val() == "") {
                 username.parent().addClass('has-error has-feedback');
                 username.parent().append('<span class="glyphicon 
glyphicon-remove form-control-feedback"></span>');
-            }else{
+            } else {
                 username.parent().removeClass('has-error has-feedback');
                 username.parent().find('span').empty().remove();
                 error = "";
             }
 
-            if(password.val() == ""){
+            if (password.val() == "") {
                 password.parent().addClass('has-error has-feedback');
                 password.parent().append('<span class="glyphicon 
glyphicon-remove form-control-feedback"></span>');
 
-                if(error == ""){
+                if (error == "") {
                     error = "Enter your password";
-                }else{
+                } else {
                     error = "Enter your username and password";
                 }
-            }else{
+            } else {
                 password.parent().removeClass('has-error has-feedback');
                 password.parent().find('span').empty().remove();
             }
             form_error.html(error).show();
             return false;
-        }else{
+        } else {
             username.parent().removeClass('has-error has-feedback');
             password.parent().removeClass('has-error has-feedback');
             password.parent().find('span').empty().remove();
@@ -61,24 +61,23 @@ $(document).ready(function(){
             form_error.hide();
             return true;
         }
-
     };
 
     //handle login ajax request
-    function loginCheck(btn){
+    function loginCheck(btn) {
         btn.button('loading');
-        if(!isValidForm()){
+        if (!isValidForm()) {
             btn.button('reset');
-        }else{
+        } else {
             $.ajax({
                 type: "POST",
                 url: caramel.context + "/controllers/login/login.jag",
                 dataType: 'json',
-                data: { username: username.val() , password: password.val() },
-                success:function(data){
-                    if(data.status ===1){
+                data: {username: username.val(), password: password.val()},
+                success: function (data) {
+                    if (data.status === 1) {
                         window.location = caramel.context;
-                    }else{
+                    } else {
                         form_error.show().html("The username or password you 
entered is incorrect.");
                     }
                 }
@@ -89,13 +88,19 @@ $(document).ready(function(){
         }
     }
 
-    username.keyup(function(){
+    username.keyup(function (e) {
+        if(e.keyCode == 13) {
+            return;
+        }
         isValidForm();
     });
-    password.keyup(function(){
+    password.keyup(function (e) {
+        if(e.keyCode == 13) {
+            return;
+        }
         isValidForm();
     });
-    
+
     // handle the submit button click event
     $('#submit-btn').click(function () {
         var btn = $(this); //get current clicked button
@@ -103,11 +108,10 @@ $(document).ready(function(){
     });// end of submit button
 
     //handle key "Enter" press
-    $(document).keypress(function(e) {
-        if(e.which == 13) {
+    $(document).keypress(function (e) {
+        if (e.keyCode == 13) {
             var btn = $('#submit-btn');
             loginCheck(btn);
         }
     });
-
 });
\ No newline at end of file

Reply via email to