Tunnels

Like validators, it is easy to write custom tunnels with Bee Form, however, the package "bee-form-tunnels" does include a number of basic tunnels for your convenience

Notice: Unlike other form libraries which also support parsing/formatting, Bee form does support parse errors, which means, when user input un-parsable values, like : "1a" for a number field we will have:

  • The field will be marked as has error, and the error name will be "@parse"
  • Form will be marked as invalid, and user will be blocked from submitting
  • Field value will be kept as "1a", so user will be able to continue changing it until it's correct. For example, is user is in middle of typing in a date string: "11/" (i.e. full string is "11/02/2018") then although we can not parse the value, we should still let user continue to type until he finishes.

JSON

import {json} from "bee-form-tunnels";

const formConfig = {
    "content": {
        tunnel: [json],
    },
};
<textarea {...fv.bind("content")} />

<pre>{JSON.stringify(fv.getData())}</pre>

Integer number

import {intNumber} from "bee-form-tunnels";

const formConfig = {
    "content": {
        tunnel: [intNumber],
    },
};
<input {...fv.bind("content")} />

<pre>{JSON.stringify(fv.getData())}</pre>

Trim

import {trim} from "bee-form-tunnels";

const formConfig = {
    "content": {
        tunnel: [trim],
    },
};
<textarea {...fv.bind("content")} />

<pre>{JSON.stringify(fv.getData())}</pre>