Advertisement
Guest User

Untitled

a guest
Jul 21st, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. angularFormsApp.directive('showErrors',['$timeout', function ($timeout) {
  2.  
  3. return {
  4. restrict: 'A',
  5. require: '^form',
  6. link: function (scope, el, attrs, formCtrl) {
  7.  
  8. // find the text box element, which has the 'name' attribute
  9. var inputEl = el[0].querySelector("[name]");
  10.  
  11. // convert the native text box element to an angular element
  12. var inputNgEl = angular.element(inputEl);
  13.  
  14. // get the name on the text box so we know the property to check
  15. // on the form controller
  16. var inputName = inputNgEl.attr('name');
  17.  
  18. var helpText = angular.element(el[0].querySelector(".help-block"));
  19.  
  20. // only apply the has-error class after the user leaves the text box
  21. inputNgEl.bind('blur', function () {
  22. el.toggleClass('has-error', formCtrl[inputName].$invalid);
  23. helpText.toggleClass('hide', formCtrl[inputName].$valid);
  24. });
  25.  
  26. scope.$on('show-errors-event', function () {
  27. el.toggleClass('has-error', formCtrl[inputName].$invalid);
  28. });
  29.  
  30. scope.$on('hide-errors-event', function () {
  31. $timeout(function () {
  32. el.removeClass('has-error');
  33. }, 0, false);
  34. });
  35.  
  36.  
  37. }
  38. }
  39.  
  40. }]);
  41.  
  42. <div class="container" id="login-form">
  43. <a href="index.html" class="login-logo"><img src="assets/img/logo-big.png"></a>
  44. <div class="row">
  45. <div class="col-md-4 col-md-offset-4">
  46. <div class="panel panel-default">
  47. <div class="panel-heading">
  48. <h2>Login Form</h2>
  49. </div>
  50. <div class="panel-body">
  51.  
  52. <form name="loginForm" class="form-horizontal" novalidate>
  53. <div class="form-group mb-md" show-errors>
  54. <div class="col-xs-12">
  55. <div class="input-group">
  56. <span class="input-group-addon">
  57. <i class="ti ti-user"></i>
  58. </span>
  59. <input type="text" class="form-control" placeholder="Username" autocomplete="Off" ng-required="true" name="username" autofocus ng-model="loginUser.username">
  60. </div>
  61. <span class="help-block" ng-if="loginForm.username.$error.required">Username is required</span>
  62. </div>
  63. </div>
  64. <div class="form-group mb-md" show-errors>
  65. <div class="col-xs-12" >
  66. <div class="input-group">
  67. <span class="input-group-addon">
  68. <i class="ti ti-key"></i>
  69. </span>
  70. <input type="password" class="form-control" placeholder="Password"
  71. name="password"
  72. ng-model="loginUser.password" autocomplete="Off"
  73. ng-required="true">
  74. </div>
  75. <span class="help-block" ng-if="loginForm.password.$error.required">Password is required</span>
  76. </div>
  77. </div>
  78. <div class="form-group mb-n">
  79. <div class="col-xs-12">
  80. <a href="extras-forgotpassword.html" class="pull-left">Forgot password?</a>
  81. <div class="checkbox-inline icheck pull-right p-n">
  82. <label for="">
  83. <input type="checkbox"></input>
  84. Remember me
  85. </label>
  86. </div>
  87. </div>
  88. </div>
  89. </form>
  90. </div>
  91. <div class="panel-footer">
  92. <div class="clearfix">
  93. <a href="extras-registration.html" class="btn btn-default pull-left">Register</a>
  94. <a href="" class="btn btn-primary pull-right" ng-click="$event.preventDefault(); SubmitLoginForm()">Login</a>
  95. </div>
  96. </div>
  97. </div>
  98.  
  99. </div>
  100. </div>
  101. </div>
  102.  
  103. var loginController = function ($scope, $window, $routeParams, $uibModal, $location, $filter, $rootScope, DataService, SharedProperties) {
  104.  
  105. $rootScope.bodylayout = 'focused-form animated-content';
  106.  
  107. $scope.loginUser = {
  108. username: "",
  109. password:""
  110. }
  111.  
  112.  
  113.  
  114. $scope.load = function () {
  115.  
  116. //getAppointmentInfo();
  117. };
  118.  
  119. $scope.SubmitLoginForm = function () {
  120. $scope.$broadcast('show-errors-event');
  121.  
  122. if ($scope.loginForm.$invalid)
  123. return;
  124. }
  125. }
  126.  
  127. angularFormsApp.controller("loginController", ["$scope", "$window", "$routeParams", "$uibModal", "$location", "$filter", "$rootScope", "DataService", "SharedProperties", loginController]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement