# @vdegenne/mwc-forms-util

> Some useful functions to manipulate forms using @material elements

Latest version **1.5.1** (published 2020-04-24) · 0 weekly downloads

## Install

```sh
npm install @vdegenne/mwc-forms-util
pnpm add @vdegenne/mwc-forms-util
yarn add @vdegenne/mwc-forms-util
bun add @vdegenne/mwc-forms-util
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2020-04-24 |
| First published | 2020-01-22 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Valentin Degenne |
| Maintainers | vdegenne |

## Links

- npm: https://www.npmjs.com/package/@vdegenne/mwc-forms-util
- npm.io page: https://npm.io/package/@vdegenne/mwc-forms-util

## Recent versions

- 1.5.1 (latest) — 2020-04-24
- 1.2.2 — 2020-04-24
- 1.5.0 — 2020-03-23
- 1.4.0 — 2020-03-23
- 1.3.0 — 2020-03-23
- 1.2.0 — 2020-03-22
- 1.1.4 — 2020-03-22
- 1.1.3 — 2020-03-20
- 1.1.2 — 2020-01-31
- 1.1.1 — 2020-01-31
- 1.1.0 — 2020-01-31
- 1.0.0 — 2020-01-22

## README

# @vdegenne/mwc-forms-util

A set of convenient methods for manipulating forms using @material elements.

> Work still in Progress
> Please don't hesitate to make some Pull Request to improve this module.

## Installation

```bash
npm i @vdegenne/mwc-forms-util
```

Then in your code

```javascript
import { ... } from '@vdegenne/mwc-forms-util';
```

*(Note: You can use this same line for TypeScript project, the typings are already included in the package).*

You can also include this package directly in your html

```html
<script type="module" src="/node_modules/@vdegenne/mwc-forms-util/util.js"></script>
```

If you have a node module path resolver server then you can just type

```html
<script type="module" src="@vdegenne/mwc-forms-util"></script>
```

## Usage

### validateForm

```javascript
if (!validateForm(formElement)) {
  console.log('something went wrong');
}
else {
  // continue
}
```

This function will also report the validity and the user-defined helper will be triggered (e.g. `mwc-textfield` will becomes red if it was required but the field is empty).

### serializeForm

Digests an object `{name: value}` representing the form.

```javascript
const object = serializeForm(formElement);
```

### fillForm

```javascript
const object = {
  name: 'Martin',
  age: 32,
  phone: '123-456
};

fillForm(formElement, object);
```

### resetForm(formElement)

Resets the form element.

---
_Source: https://npm.io/package/@vdegenne/mwc-forms-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
