Get started with formjs CDN

MIT licensed

FormJS is a lightweight library for managing and validating web forms.

Tags:
  • form
  • framework
  • css
  • javascript
  • jquery

Stable version

Copied!

How to start using formjs CDN


// Include FormJS CDN
const Form = window.Form;
const FormDataProcessor = window.FormDataProcessor;

// Initialize a new Form instance
const form = new Form('#my-form', {
  fields: {
    name: {
      type: 'text',
      validators: {
        notEmpty: {}
      }
    },
    email: {
      type: 'email',
      validators: {
        notEmpty: {},
        emailAddress: {}
      }
    }
  }
});

// Initialize a new FormDataProcessor instance
const processor = new FormDataProcessor(form);

// Attach submit event to the form
document.querySelector('#my-form').addEventListener('submit', (e) => {
  e.preventDefault();
  processor.submit();
});
Copied!
Copied!
Copied!
Copied!

All versions