LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

GentleForm

Accessible and user-friendly HTML5 form validation library.
GitHub Repo - Tweet!

This field is required.
This field is required. Please enter a valid email address.
Please enter a valid phone number.
This field is required. Your password should be at least 6 characters long.
CSS
/*---------------------------------------------*\
    variables
\*---------------------------------------------*/
/*---------------------------------------------*\
    styles
\*---------------------------------------------*/
*,
*:before,
*:after {
  box-sizing: inherit;
}

html,
body {
  height: 100%;
}

.wrapper {
  min-height: 100%;
}

html {
  font-size: 16px;
  box-sizing: border-box;
}

body {
  font-size: 1rem;
  line-height: 1.4;
  font-family: "Source Sans Pro", Helvetica, Arial, sans-serif;
  font-weight: 300;
  color: #002c3c;
  background-color: #f4fcff;
}

small {
  font-size: .8rem;
}

h1 {
  display: inline-block;
  font-family: "Francois One", sans-serif;
  font-size: 3rem;
  line-height: 1.2;
  font-weight: 700;
  margin: 0 0 .8rem 0;
  border-bottom: 4px solid #31d47d;
}

p {
  margin: 0 0 2rem 0;
}

a {
  color: #31d47d;
  text-decoration: none;
}
a:focus, a:hover {
  color: #24ae64;
}

.text-muted, footer {
  color: #a9bec6;
}

.wrapper {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
}

.section-form {
  padding: 0 20px;
}

.form {
  display: block;
  max-width: 400px;
}

.form-group {
  margin-bottom: 20px;
}

.form-label,
.form-input {
  display: block;
  width: 100%;
}

.form-label {
  cursor: pointer;
  margin-bottom: 5px;
}

.form-label--required {
  position: relative;
}
.form-label--required:before {
  content: "*";
  position: absolute;
  left: -10px;
  color: #f42866;
}

.form-input {
  padding: 10px;
  background-color: transparent;
  border: 0;
}
.form-input:focus {
  outline: none;
  background-color: #f0f7f9;
}

.form-footer {
  text-align: right;
}

.form-error {
  color: #f42866;
  margin-top: 5px;
}

.button {
  color: white;
  white-space: nowrap;
  background-color: #31d47d;
  padding: 10px 20px;
  border: 0;
  border-radius: 2px;
  -webkit-transition: all 150ms ease-out;
  transition: all 150ms ease-out;
}
.button:focus, .button:hover {
  background-color: #219d5b;
}

.form-addon {
  position: relative;
  display: table;
  width: 100%;
  border: 1px solid #bcdae5;
  background-color: #fff;
  border-radius: 2px;
}
.form-addon .form-input,
.form-addon .form-addon__addon {
  display: table-cell;
  vertical-align: middle;
}
.form-addon .form-input {
  width: 100%;
}
.form-addon .form-addon__addon {
  position: relative;
  width: 40px;
  text-align: center;
}
.form-addon .form-addon__addon:before {
  content: "";
  position: absolute;
  top: 4px;
  right: 0;
  height: calc(100% - 8px);
  border-right: 1px solid #bcdae5;
}

.form-addon__icon {
  position: absolute;
  color: #31d47d;
  font-size: .8rem;
  line-height: 1;
  top: 50%;
  -webkit-transform: translateY(-50%);
          transform: translateY(-50%);
  right: 10px;
}

.toaster {
  position: fixed;
  z-index: 1;
  top: 10px;
  right: 10px;
}

.toast {
  color: #fff;
  padding: 20px;
  margin-bottom: 10px;
  border-radius: 2px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  opacity: 0;
  -webkit-transform: translateY(-10px) rotateY(40deg);
          transform: translateY(-10px) rotateY(40deg);
  -webkit-transition: all 300ms ease;
  transition: all 300ms ease;
}
.toast.toast--show {
  -webkit-transform: translateY(0) rotateY(0);
          transform: translateY(0) rotateY(0);
  opacity: 1;
}

.toast--success {
  background-color: #31d47d;
}

.toast--error {
  background-color: #f42866;
}

footer {
  margin-top: 10px;
}

/*---------------------------------------------*\
    GentleForm related styles
\*---------------------------------------------*/
.form-addon .form-addon__icon {
  -webkit-transform: translateY(0);
          transform: translateY(0);
  opacity: 0;
  -webkit-transition: opacity 150ms ease, -webkit-transform 150ms ease;
  transition: opacity 150ms ease, -webkit-transform 150ms ease;
  transition: transform 150ms ease, opacity 150ms ease;
  transition: transform 150ms ease, opacity 150ms ease, -webkit-transform 150ms ease;
}
.form-addon.is-valid [class*="icon-valid"], .form-addon.is-invalid [class*="icon-invalid"] {
  -webkit-transform: translateY(-50%);
          transform: translateY(-50%);
  opacity: 1;
}
.form-addon.is-invalid {
  background-color: #fef4f7;
  border-color: #f989ab;
}
.form-addon.is-invalid .form-addon__icon {
  color: #f42866;
}
.form-addon.is-invalid .form-addon__addon:before {
  border-color: #f989ab;
}
JS
// This is a demo of GentleForm:
// https://github.com/Zhouzi/GentleForm

const toaster = document.getElementsByClassName('toaster')[0]
const form = document.querySelector('form')

GentleForm(form, function (event) {
  event.preventDefault()
  
  if (this.isValid()) addToast('success', 'Yay, the form is valid!')
  else addToast('error', 'Oops, the form is invalid.')
})

function addToast (type, message) {
  const toast = document.createElement('div')

  toast.classList.add('toast')
  toast.classList.add('toast--' + type)
  toast.innerHTML = message

  toaster.appendChild(toast)

  toast.addEventListener('transitionend', function (event) {
    if (event.propertyName !== 'transform') return

    if (toast.classList.contains('toast--show')) {
      setTimeout(function () {
        toast.classList.remove('toast--show')
      }, 3000)
    } else {
      toaster.removeChild(toast)
    }
  }, false)

  setTimeout(() => toast.classList.add('toast--show'), 100)
}
Host Instantly Drag and Drop Website Builder

 

Description

Validate forms at the right time, using browser's native api.
Term
Mon, 11/27/2017 - 21:56

Related Codes

Pen ID
Pen ID
Pen ID