Guest User

Untitled

a guest
Nov 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title></title>
  5. <link rel="stylesheet" href="css/style.css">
  6. <style>
  7. html { height: 100%; }
  8. body {
  9. font-family: sans-serif;
  10. font-weight: 300;
  11. font-size: 20px;
  12. background: linear-gradient(to top, #e0e7ef, #eef2f7);
  13. min-height: 100%;
  14. color: #798594;
  15. line-height: 1.6;
  16. }
  17.  
  18. form {
  19. background: #f8fafb;
  20. padding: 3em 1em;
  21. border-radius: 3px;
  22. box-shadow: 0 0.1em 0.4em #b7ccde;
  23. max-width: 15em;
  24. margin: 2em auto;
  25. }
  26.  
  27. button, input, textarea, select {
  28. font: inherit;
  29. color: inherit;
  30. padding: 0.4em 0.6em;
  31. border: 1px solid #ccc;
  32. border-radius: 4px;
  33. width: 100%;
  34. box-sizing: border-box;
  35. margin-bottom: 0.5em;
  36. }
  37.  
  38. button { cursor: pointer; background-color: #e9f1ff; color: #7e93b7; }
  39. input { display: block; position: relative; z-index: 1; }
  40. input::placeholder { color: #bbb; }
  41.  
  42. .invalid { box-shadow: 0 0.15em 0.15em -0.1em rgba(4, 4, 4, 0.1); }
  43.  
  44. .error {
  45. display: none;
  46. margin-bottom: 0.5rem;
  47. margin-top: calc(-0.5rem - 4px);
  48. margin-left: 2px;
  49. margin-right: 2px;
  50. padding: calc(0.5rem + 4px) 0.6rem;
  51. background-color: #ffefeb;
  52. color: #b75a41;
  53. border: 1px solid #e6917a;
  54. border-radius: 0 0 4px 4px;
  55. animation: show-error .3s;
  56. font-size: 0.8em;
  57. }
  58.  
  59. .invalid + .error { display: block; }
  60.  
  61. @keyframes show-error {
  62. from { transform: translateY(-100%) scaleY(0.2); }
  63. to { transform: none; }
  64. }
  65. </style>
  66. </head>
  67. <body>
  68. <form>
  69. <input type="number" placeholder="Enter 42" min="42" max="42" required>
  70. <input type="email" placeholder="Enter your email" required>
  71. <button type="submit">Register</button>
  72. </form>
  73.  
  74.  
  75. <script>
  76. // 1. Disable native validation UI with `noValidate`
  77. // 2. On submit, run evaluation and prevent if necessary
  78. const form = document.querySelector('form');
  79. form.noValidate = true;
  80. form.onsubmit = evt => {
  81. if (!form.checkValidity()) evt.preventDefault();
  82. };
  83.  
  84.  
  85. for (let field of form.querySelectorAll('input, textarea, select')) {
  86. // Add error container
  87. field.insertAdjacentHTML('afterend', '<div class="error"></div>');
  88.  
  89. // Show message on `invalid` event
  90. field.oninvalid = () => {
  91. field.classList.add('invalid');
  92. field.nextSibling.textContent = field.validationMessage;
  93.  
  94. // Reset invalid state & error message on `input` event, trigger validation check
  95. field.oninput = () => {
  96. field.oninput = null;
  97. field.nextSibling.textContent = '';
  98. field.classList.remove('invalid');
  99. field.checkValidity();
  100. };
  101. };
  102. }
  103. </script>
  104. </body>
Add Comment
Please, Sign In to add comment