1.0.1 • Published 2 years ago

formaggino v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

GitHub

🧀 Formaggino

A small vanilla js library for validate your forms without external dependencies

Getting started

Install the package

npm install formaggino

Initialize the library

import Formaggino from "formaggino";
const formaggino = new Formaggino();

Create a form remember to include method, action and novalidate on your form

<form
  method="POST"
  id="form"
  action="https://your-action.io/sendform"
  novalidate
>
  <input name="name" type="text" required />
  <span class="form-error">Your error text</span>
  ...
  <div class="form-report-error">error</div>
  <div class="form-report-success">success</div>
  <span class="form-loading"> loading... </span>
  <button type="submit">submit</button>
</form>

call the submitEvent method

formaggino.submitEvent("#form");

or use the options

formaggino.submitEvent("#form"{
  mode: 'json',
  loadingClass: 'your-loading__custom_class',
  closingTimint: 8000
  ...
});

don't forget to set you css

.form-error,
.invalid-feedback,
.form-loading,
.form-report-error,
.form-report-success {
  display: none;
}

.active {
  display: block;
}

Options

OptionTypeDefaultDescription
modestringform-datathe type of data to send to fetch request, you can also use json
loadingClassstringform-loadingthe css class for loading element
errorClassstringform-errorthe css class for each single field of form
formSuccessstringform-report-successthe css class for form success element
formErrorstringform-report-errorthe css class for form error element
closingTiminginteger3000timeout for form report duration
listenerstringchangethe event listener for each single field in form

Contributing

Build for development

  • Having all the dependencies installed run npm run dev. This command will generate UMD (unminified), CommonJS and ESM modules under the dist folder. It will also watch for changes in source files to recompile.

Build for production

  • Having all the dependencies installed run npm run build. This command will generate the same modules as above and one extra minified UMD bundle for usage in browser.

Scripts

  • npm run build - Produces production version of library modules under dist folder.
  • npm run dev - Produces a development version of library and runs a watcher to watch for changes.
  • npm run test - Runs the tests.
  • npm run lint - Lints the source code with ESlint.
  • npm run prepare - Run both BEFORE the package is packed and published, on local npm install without any arguments, and when installing git dependencies.
  • npm run clean - Deletes dist and coverage folders.
  • npm run serve - serve the index.html with http-server

License

The MIT License (MIT)

1.0.1

2 years ago

1.0.0

2 years ago