# forms-dynamically

> Converts html forms into JSON and back.

Latest version **1.2.1** (published 2020-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install forms-dynamically
pnpm add forms-dynamically
yarn add forms-dynamically
bun add forms-dynamically
```

## 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.2.1 |
| Published | 2020-12-31 |
| First published | 2020-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Muskan Vaswan |
| Maintainers | muskanvaswan |
| Keywords | Forms, JSON, HTML, Convert, Generate |

## Links

- npm: https://www.npmjs.com/package/forms-dynamically
- npm.io page: https://npm.io/package/forms-dynamically

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.1 (latest) — 2020-12-31
- 1.2.0 — 2020-12-31
- 1.0.1 — 2020-12-28
- 1.0.0 — 2020-12-27

## README

# forms-dynamically
This is a npm package that allows you to convert an HTML Form to JSON and back
## Installation
```bash
npm i forms-dynamically
```
OR
```HTML
<script src="https://unpkg.com/forms-dynamically@1.2.1/forms.min.js"></script>
```

## Usage


### **formToJson(id)**
*arguments required : Id of form element*

*returns: JSON object with structure*

Reads input elements of the form one by one and then stores them in a JSON format

e.g.

```HTML
<form id="testForm">

  <input type="text" id="name" name="name" placeholder="What is your name?">

  <input type="number" id="age" name="age" class="agefield">

</form>
```

Suppose there is a form like above in the HTML of any page.

When formToJson("testForm") is called it should return something like this

```json
{
"formId": "testForm",
"elements": [{
    "elementType": "input",
    "type": "text",
    "id": "name",
    "name": "name",
    "placeholder": "What is your name"
  },
  {
    "elementType": "input",
    "type": "number",
    "id": "age",
    "name": "age",
    "class": "agefield"

  }
]
}
```

Note : This is just a suggestive JSON. You can define your own structure.
The idea is to be able to store a structure of the form in JSON format.

### jsonToForm(jsonObject)
*arguments JSON object with structure mentioned above*

*returns: HTML for the form rendered with the given structure*

The **jsonToForm()** function will parse the JSON which we generated in the previous function and generate
a form HTML and populate the form HTML in the div given with targetDivId

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