Socket
Book a DemoInstallSign in
Socket

virtual-form

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

virtual-form

Create a virtual-dom form

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

virtual-form

NPM version build status Test coverage Downloads js-standard-style

Create a virtual-dom form.

Installation

$ npm install virtual-form

Usage

const virtualForm = require('virtual-form')
const vel = require('vel')

vel(function (h) {
  return h('form.myForm', virtualForm(h, [
    'name',
    'address',
    { type: 'password', name: 'passphrase' },
    { type: 'submit', value: 'Submit' }
  ])
})

output

<form class="myForm">
  <input type="text" name="name" placeholder="name">
  <input type="text" name="address" placeholder="address">
  <input type="password" name="passphrase" placeholder="passphrase">
  <input type="submit" value="Submit">
</form>

API

formContent = virtualForm(h, [opts,] elements)

Create new form content. There are several types of elements that can be created:

simple

h('form', virtualForm(h, [
  'address'
]))
<form>
  <input type="text" name="address" placeholder="address">
</form>

custom

h('form', virtualForm(h, [
  { type: 'password', name: 'passphrase' }
]))
<form>
  <input type="password" name="passphrase" placeholder="passphrase">
</form>

label

h('form', virtualForm(h, { label: true }, [
  'address'
]))
<form>
  <input type="text" name="address" placeholder="address">
  <fieldset>
    <label>address</label>
    <input type="text" name="address">
  </fieldset>
</form>

FAQ

Why isn't the form element created too?

Creating a flat array of inputs has a significantly simpler interface than when a form element is also created. For instance, users might want to attach listeners to ev-submit or set classes.

Why does h need to be passed in?

Though virtual-dom is lightweight, if every package pulls in their own version, file size quickly grows. Instead it's better to pull in virtual-dom once and pass references down throughout the application.

See Also

License

MIT

Keywords

virtual dom

FAQs

Package last updated on 03 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts