4.45.4 • Published 2 months ago

tangy-form v4.45.4

Weekly downloads
435
License
ISC
Repository
github
Last release
2 months ago

\<tangy-form>

Published on webcomponents.org Greenkeeper badge Build Status

An element for multipage forms.

  • Conforms to Material Design guidelines.
  • Loads of handy input elements such as <tangy-gps>.
  • Easy to write logic for the form for hiding / showing and disabling / enabled inputs.

Try out the demos on Glitch or get started creating your own Tangy Form on CodePen or Glitch.

screenshot

<tangy-form id="my-form">
  <tangy-form-item id="item1">
    <tangy-input name="input1" label="What is your first name?"></tangy-input>
  </tangy-form-item>
  <tangy-form-item id="item2">
    <tangy-input name="input2" label="What is your last name?"></tangy-input>
  </tangy-form-item>
</tangy-form>

<script>
  document.querySelector('#my-form').addEventListener('submit', event => {
    // By default, the form response is locked and the user can browse it. Use event.preventDefault() 
    // to do something else.
    event.preventDefault()
    // 3 ways to inspect the user's response to the form. Ordered by level of detail.
    console.log(event.target.response)
    console.log(event.target.inputs)
    console.log(event.target.values)
  })
</script>

Tangy-form also has some convenience methods to disable inputs and item buttons - an easy way to display form results:

  • enableItemReadOnly() - disables the inputs in the form
  • hideItemButtons() - hides the Open/Close buttons

screenshot

You can re-enable the form by using disableItemReadOnly() (and showItemButtons(), if necessary).

Installation

<tangy-form> is a Custom Element built with Polymer and can be used in frameworks such as Angular, React, and Vue. Check compatibility with your project's framework on Custom Elements Everywhere. If you are ready to go, run npm install --save tangy-form to add it to your project. Depending on your build system/framework, there may be different steps to take to get Web Components loading.

Install using the CDN

A quick and easy way to get started with Tangy Form in your app is to add the necessary script tags to import dependencies from CDNs. The following should be all you need to get started.

  <script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.2.10/webcomponents-loader.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/redux/4.0.4/redux.js"></script>
  <script src="https://unpkg.com/tangy-form@3.21.0/dist/bundle.js" type="module"></script>

Install in a Polymer v3 project

npm install --save tangy-form

Because Redux is not playing nicely with bundlers, you need to include it as a global dependency in a script tag as you will see in the demo/index.html.

Then from any of your elements, import tangy-form.

import 'tangy-form/tangy-form.js'

Install in an Angular v4+ project

Run on the command line...

npm install --save tangy-form redux @webcomponents/webcomponentsjs

Then add to your ./polyfills.ts file...

import * as Redux from 'redux';
(window as any).Redux = Redux;
import '@webcomponents/webcomponentsjs/webcomponents-sd-ce.js';
import 'tangy-form/tangy-form.js'

Lastly, any module where you are going to use a Web Component you need to let Angular know it can be flexible with the names of components by import CUSTOM_ELEMENTS_SCHEMA. Note that just enabling on the app module level is not enough for children modules to also use flexible schema. You need to do the same for those children modules as well.

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
...
@NgModule({
  declarations: [
    AppComponent
  ],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
...

Install Tangy Input elements

Due to the growing number of Tangy input elements, you'll need to specify which Tangy input elements to include in your application with additional import statements. See the input folder for a list of elements and import them using...

import 'tangy-form/input/tangy-input.js'
import 'tangy-form/input/tangy-radio-buttons.js'
import 'tangy-form/input/tangy-checkboxes.js'

Theming

You can provide some CSS overrides by providing a custom style definition in your app's index.html.

<custom-style>
  <style>
    html {
      --document-background-color: #FAFAFA;
      --primary-color-dark: #3c5b8d;
      --primary-text-color: var(--light-theme-text-color);
      --primary-color: #3c5b8d;
      --accent-color: #f26f10;
      --accent-text-color: #FFF;
      --error-color: var(--paper-red-500);
      --warn-color: #993f0b;
      --warn-background-color: #f4e688;
      --disabled-color: #BBB;
    }
    h1, h2, h3, h4, h5 {
      @apply --paper-font-common-base;
      color: var(--primary-text-color);
      margin: 25px 0px 5px 15px;
    }
  </style>
</custom-style>

Logic

The tangy-if and valid-if properties can be added to inputs to provide conditional logic to a form. Here is an example for a tangy-form-item reveals a tangy-box if the user does not input the desired selection in a tabgy-checkboxes input:

<tangy-form-item id="item1">
<tangy-checkboxes name="input1" label="What is your favorite fruit?" valid-if="getValue('input1')[0] === 'Tangerine'">
  <option name="orange">Orange</option>
  <option name="banana">Banana</option>
  <option name="tangerine">Tangerine</option>
  <option name="cantalope">Cantalope</option>
  <option name="cherry">Cherry</option>
  <option name="kiwi">Kiwi</option>
</tangy-checkboxes>
<tangy-box tangy-if="inputs.input1.invalid === true">
  You really should consider liking tangerines.
</tangy-box>
</tangy-form-item>

See tests/tangy-form-item_test.html for examples for other inputs.

The exposeHelperFunctions function in tangy-form-item.js exposes helper functions that may be used in tangy-if and valid-if statements. The most commonly used function is getValue(name). It checks the value of a named input first in the DOM and then (if not found in the DOM) in the redux store.

Run the demo

Requires node.js and npm installed.

git clone https://github.com/tangerine-community/tangy-form
cd tangy-form
npm install
npm start

Then open http://localhost:8080

Tests

As of v4.41.0, tests are currently non-working, throwing a mocha-related error.

One of the best places to learn about what Tangy Form is capable of is to take a look at the tests in test/tangy-form_test.html. To run tests, use polymer test command or just npm run test to just run tests in Chrome. If you want to develop tests, open http://localhost:8080/test/tangy-form_test.html

Note you will need Java 8 installed in order to run tests. Info on installing Java 8 or uninstalling Java X to install Java 8 can be found here.

If running on a Mac with the M1 processor, you must run node node_modules/polymer-cli/node_modules/wd/scripts/build-browser-scripts.js in order to avoid the error cli runtime exception: Error: Cannot find module '../build/safe-execute'

4.45.4

2 months ago

4.45.3

2 months ago

4.45.2

3 months ago

4.45.1

4 months ago

4.45.0

4 months ago

4.43.2

6 months ago

4.43.2-rc.3

9 months ago

4.43.2-rc.2

9 months ago

4.43.2-rc.1

9 months ago

4.43.2-rc.0

9 months ago

4.43.1-rc.4

9 months ago

4.43.1-rc.3

9 months ago

4.43.1-rc.2

9 months ago

4.43.1-test.0

9 months ago

4.43.1

9 months ago

4.43.1-rc.1

9 months ago

4.43.1-rc.0

9 months ago

4.43.0

9 months ago

4.42.0

12 months ago

4.41.1

1 year ago

4.40.0

2 years ago

4.39.1

2 years ago

4.39.3

2 years ago

4.39.2

2 years ago

4.38.2

2 years ago

4.38.1

2 years ago

4.38.0

2 years ago

4.38.3

2 years ago

4.37.1

2 years ago

4.37.0

2 years ago

4.36.3

2 years ago

4.36.2

2 years ago

4.36.1

2 years ago

4.36.0

2 years ago

4.35.1

2 years ago

4.35.0

2 years ago

4.34.5

2 years ago

4.34.3

3 years ago

4.31.0

3 years ago

4.30.0

3 years ago

4.33.2

3 years ago

4.33.1

3 years ago

4.32.1

3 years ago

4.34.2

3 years ago

4.34.1

3 years ago

4.34.0

3 years ago

4.29.1

3 years ago

4.29.2

3 years ago

4.29.3

3 years ago

4.29.4

3 years ago

4.28.2

3 years ago

4.28.3

3 years ago

4.28.1

3 years ago

4.28.0

3 years ago

4.27.0

3 years ago

4.26.0

3 years ago

4.25.14

3 years ago

4.25.13

3 years ago

4.25.12

3 years ago

4.25.11

3 years ago

4.25.10

3 years ago

4.25.5

3 years ago

4.25.6

3 years ago

4.25.7

3 years ago

4.25.8

3 years ago

4.25.9

3 years ago

4.25.4

3 years ago

4.25.0

4 years ago

4.24.0

4 years ago

4.23.3

4 years ago

4.23.2

4 years ago

4.23.1

4 years ago

4.23.0

4 years ago

4.22.1

4 years ago

4.22.0

4 years ago

4.21.3

4 years ago

4.21.2

4 years ago

4.21.1

4 years ago

4.21.0

4 years ago

4.20.1

4 years ago

4.20.0

4 years ago

4.19.1

4 years ago

4.19.0

4 years ago

4.18.0

4 years ago

4.17.10

4 years ago

4.17.9

4 years ago

4.17.8

4 years ago

4.17.7

4 years ago

4.17.6

4 years ago

4.17.5

4 years ago

4.17.4

4 years ago

4.17.3

4 years ago

4.17.2

4 years ago

4.16.0

4 years ago

4.15.4

4 years ago

4.15.0

4 years ago

4.14.1

4 years ago

4.14.0

4 years ago

4.13.1

4 years ago

4.13.0

4 years ago

4.12.3

5 years ago

4.12.2

5 years ago

4.12.1

5 years ago

4.12.0

5 years ago

4.11.5

5 years ago

4.11.4

5 years ago

4.11.3

5 years ago

4.11.2

5 years ago

4.11.1

5 years ago

4.11.0

5 years ago

4.10.4

5 years ago

4.10.3

5 years ago

4.10.2

5 years ago

4.9.0

5 years ago

4.10.1

5 years ago

4.10.0

5 years ago

4.8.1

5 years ago

4.8.0

5 years ago

4.7.1

5 years ago

4.7.0

5 years ago

4.6.3

5 years ago

4.6.2

5 years ago

4.6.1

5 years ago

4.6.0

5 years ago

4.5.4

5 years ago

4.5.3

5 years ago

4.5.2

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.1

5 years ago

4.4.0

5 years ago

4.3.9

5 years ago

4.3.8

5 years ago

4.3.7

5 years ago

4.3.6

5 years ago

4.3.5

5 years ago

4.3.4

5 years ago

4.3.3

5 years ago

4.3.2

5 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.0

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.23.0

5 years ago

3.22.1

5 years ago

3.22.0

5 years ago

3.21.0

5 years ago

3.20.0

5 years ago

3.19.0

5 years ago

3.18.0

5 years ago

3.17.0

5 years ago

3.16.1

5 years ago

3.16.0

5 years ago

3.15.1

5 years ago

3.15.0

6 years ago

3.14.0

6 years ago

3.13.0

6 years ago

3.12.2

6 years ago

3.12.1

6 years ago

3.12.0

6 years ago

3.11.0

6 years ago

3.10.2

6 years ago

3.10.1

6 years ago

3.10.0

6 years ago

3.9.1

6 years ago

3.9.0

6 years ago

3.8.0

6 years ago

3.7.1

6 years ago

3.7.0

6 years ago

3.6.0

6 years ago

3.5.0

6 years ago

3.4.1

6 years ago

3.4.0

6 years ago

3.3.2

6 years ago

3.3.1

6 years ago

3.3.0

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

2.11.2

6 years ago

3.0.0

6 years ago

2.11.1

6 years ago

2.11.0

6 years ago

2.10.1

6 years ago

2.10.0

6 years ago

2.9.3

6 years ago

2.9.2

6 years ago

2.9.1

6 years ago

2.9.0

6 years ago

2.8.1

6 years ago

2.8.0

6 years ago

2.7.0

6 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.1

6 years ago

2.5.0

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.8

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago