Skip to content

Latest commit

 

History

History
89 lines (74 loc) · 3.13 KB

README.md

File metadata and controls

89 lines (74 loc) · 3.13 KB

Published on webcomponents.org

Polymer 1 element for extracting data out of forms. Part of Falcon.io - Build Elements bundle.

<script src="../webcomponentsjs/webcomponents-lite.js"></script> ```html Choice ```

<build-form-schema-extractor> attempts to extract a json schema from a html form using built-in or provided rules to transform the form fields into json schema properties. It will continously update the scheme according to the fields that is currently in the provided form. Example:

    <form id="myForm">
        <input type="text" required name="fullname" placeholder="Full Name">
        <input type="email" name="email" placeholder="Email">
        <input type="number" name="age" placeholder="Age">
        <input type="checkbox" name="choice">Choice
    </form>
    <build-form-schema-extractor
        form="myForm"
        schema="{{ schema }}"
    ></build-form-schema-extractor>

Which would extract in this json scheme

    {
        "type": "object",
        "properties": {
            "fullname": {
                "title": "Full Name",
                "type": "string"
            },
            "email": {
                "title": "Email",
                "type": "string",
                "format": "email"
            },
            "age": {
                "title": "Age",
                "type": "number"
            },
            "choice": {
                "title": "Choice",
                "type": "boolean"
            }
        },
        "required": ["fullname"]
    }

The following form field attributes gets transformed by default

field name function schema name
id Can be used for internal reference id
minlength Specifies the minimum number of characters minLength
maxlength Specifies the maximum number of characters maxLength
min Specifies the minimum value minimum
max Specifies the maximum value maximum
required Specifies that an input field is required (must be filled out) becomes part of required array
placeholder title for field title
label title for field if placeholder is not specified title

Running demos and tests in browser

Running tests from the command line

When in the falconio-form-schema-extractor directory, run polymer test

License

MIT License