0.0.4 • Published 4 years ago

@idris-maps/form v0.0.4

Weekly downloads
-
License
GPLv2
Repository
-
Last release
4 years ago

@idris-maps/form

Define forms in JSON. This library makes no assumptions about esthetics, use your own CSS.

Usage

without a bundler

<html>
  <body>
    <div id="login-form"></div>
    <script src="form.js"></script>
    <script>

form(document.getElementById('login-form'), {
  fields: [
    { type: 'email', property: 'email' },
    { type: 'password', property: 'password', minLength: 8  },
  ],
  submit: {
    method: 'POST',
    url: 'https://my.api/login',
    errorMessage: 'You are not welcome here',
    successRedirectUrl: '/home',
  },
})

    </script>
  </body>
</html>

Download form.js here.

with a bundler

npm install @idris-maps/form

Types are included.

import form, { Field, SubmitAction } from '@idris-maps/form'

const fields: Field[] = [
  { type: 'email', property: 'email' },
  { type: 'password', property: 'password', minLength: 8  },
]

const submit: SubmitAction = {
  method: 'POST',
  url: 'https://my.api/login',
  errorMessage: 'You are not welcome here',
  successRedirectUrl: '/home',
}

form(document.getElementById('login-form'), {
  fields,
  submit,
})

See the type definitions for more details.

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago