0.9.14 ā€¢ Published 5 years ago

@calderajs/forms v0.9.14

Weekly downloads
2
License
GPL-2.0
Repository
-
Last release
5 years ago

Forms For Caldera

This is a React component library for forms. It is designed to be used in Caldera UIs, including Caldera Forms.

Install

yarn add @calderajs/forms

Testing

  • Run Unit Tests - Jest.

    • yarn tests
  • Run Storybooks

    • yarn storybook

Other Commands

  • Lint code
    • yarn lint
  • Build Package
    • yarn package
    • The output is stored in the dist folder.
  • Run tests once for CI
    • yarn test:ci

Usage

<CalderaForm />

This component is used for all forms in the Caldera Framework. The Caldera Forms front-end (Caldera Forms 2.0+) and all UI sections.

This component uses Formik for managing state and validation. The layout uses the CalderaGrid component of this package and uses the fieldAreaFactory from the calderawp/@factory package.

Why Formik?

I originally wanted to use redux-forms. I didn't love the API or the validation. Also, I had a less articulate version of these conncerns. We're using more of Formik's features than you need to create a working form. Formik feels like it does the basics really well and everything is extensible.

Specific benefits:

  • We are not developing our own validation system.
  • Loop Fields/ Repeater Fields: Totally Covered.
  • Great Documentation
  • Allows us to supply our own field components, CSS, layouts, etc.
    • Formik has text, select, textarea fields, but we don't have to use them.

Import With webpack

import {CalderaForm} from '@calderajs/forms';

Creating a form

The Caldera Forms component is totally decoupled from Caldera Forms 1.x form submission. The <CF2Form /> component is designed to be used with Caldera Forms 1.9 or later.

<CalderaForm
    form={form}//form config
    onSubmit={(
        //current values of all fields
        values, 
        actions
    ) => {
        setTimeout(() => {
            alert(JSON.stringify(values, null, 2));
            actions.setSubmitting(false);
        }, 1000);
    }}
    onChange={(values) => {
        console.log(values) //all field values
    }}
	/>
Props
  • formRows - Object - The form layout.
  • onSubmit Function - Called when form is submitted by Formik.onSubmit()
  • onChange Function - Called when any field is changed.
    • Is passed all updated field values.
  • initialValues - Object. Initial values for all fields in form. Mapped fieldId : fieldValue
Shape Of Form
  • id - string
  • name - string
  • fields - array
  • conditionals - array
  • rows - array
import{createFieldRule} from '@calderajs/forms';
const form = {
	id: 'contact-form',
	name: 'Contact Form',
	rows : [
	    {
	    	rowId: 'r1',
	    	columns: [
	    		{
	    			columnId: 'c1',
	    			fields: ['sendEmail'],
	    			width: '1/4'
	    		},
	    		{
                    columnId: 'c2',
                    fields: ['primaryEmail'],
                    width: '3/4'
                }
	    	]
	    }	
	],
	fields:[
		{
            type: 'select',
            fieldId: 'sendEmail',
            label: 'Would you like to provide an email?',
            options: [
            	{optionValue: true, label: 'Yes' },
            	{optionValue: false, label: 'No' },
            ]
        },
		{
			type: 'input',
			fieldId: 'primaryEmail',
			html5type: 'email',
			label: 'Your Email'
		}
	],
	conditionals: [
		{
			//result of conditional
			type: 'hide',
			//Logic of conditional
			rule: createFieldRule('is', 'sendEmail', true ),
			//fields effected by conditional
			fields: [
				'primaryEmail'
			]
		}
	]
}

<CF2Form>

Wrapper for <CalderaForm /> designed to be used with the "cf2" API in Caldera Forms 1.x.

šŸŒ‹šŸ‘€Documentation

<HorizontalForm>

Wrapper for <CalderaForm /> where every field is in its own 100% wide row. Useful for Gutenberg block settings for field settings in Caldera Forms form builder.

šŸŒ‹šŸ‘€Documentation

MailChimp Forms

Mailchimp sign up and survey forms. šŸŒ‹šŸ‘€Documentation

Contact Form

šŸŒ‹šŸ‘€Documentation

Clients

See the clients Readme

0.9.14

5 years ago

0.9.14-alpha.0

5 years ago

0.9.12

5 years ago

0.9.12-alpha.4

5 years ago

0.9.12-alpha.3

5 years ago

0.9.10

5 years ago

0.9.8

5 years ago

0.9.7

5 years ago

0.9.6

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago