cofi

cofi

  • Docs
  • Form Demos
  • Components Demos
  • Layout Demos
  • Editor
  • GitHub

›Form Class

Getting started

  • Introduction

Form Class

  • Installation
  • Overview
  • Arguments
  • Id
  • Data
  • Fields
  • Path
  • Component
  • Formatter & Parser
  • Dependencies
  • Required
  • Validators
  • Exclude Term
  • Disable Term
  • Require Term
  • Dependencies Change
  • Context
  • Dirty
  • Invalid
  • Errors
  • Processing
  • Pending Actions
  • Hooks
  • Term
  • Log
  • Error Codes
  • Actions
  • Definition Shorthand

Advanced Usages

  • Grid Usage
  • Form Persistency
  • Undo & Redo
  • Replay Actions
  • Track Actions
  • Server Validation
  • Entity Templates
  • Folder Structure

React Form

  • Installation
  • Overview
  • Form
  • Field
  • Components
  • Layout
  • Demos

Tools

  • Editor
  • DevTools

More Info

  • Test Cofi
  • Packages
  • Why Cofi?
  • Technologies
  • Videos
  • Channels

Contribute

  • Code of Conduct
  • Contributing Guide
  • Contributors

Fields

required object - Object which represents the form's fields. key is the id of the field and value is its props. Each field defines the path in the form data, necessary validations, which UI component it's using (for instance, checkboxList), and other extra definitions.

Field key

unique string - unique field id per form.

Example:

'firstName' | 'email' | '12345' | 'e345swer456ef'

Note: A recommended practice is to define id as closest to the field path as you can, for instance: path of 'email' define key of 'email', and for path of 'addresses.work' define id of 'addressesWork'.

Note: Field path is not the field key (id), in-order to allow definition of 1+ different fields (with different components) with the same path. For example, In a video details page, use 2 fields that has path of 'id' which represents video.id data - the first field shows id as string (using label component), and the second field shows the video itself in a player component.

Field value

object - contains the following field properties:

NameTypeDefaultDescription
pathrequired stringObject path to a specific value in the model data. More info
labelstringundefinedBy default, renders above the field's component to show the field label
descriptionstringundefinedBy default, renders next to the component's label to represent the field description
componentobjectundefinedRepresent a ui component of a field, such as DatePicker, Text, Number and and custom component. More info
formatterobjectundefinedDefine formatter to a field component definition when the field's value structure is different then the structure that the component can handle. More info
parserobjectundefinedDefine parser to a field component definition when the field's value structure is different then the structure that the component can handle. More info
dependenciesstring arrayundefinedRepresent an array of fields ids that the current field is depended on at any time of the field's evaluation. More info
dependenciesChangeobjectundefinedDefine dependencies change for a field, in order to change its value / state when another field has changed its value. More info
validatorsobject arrayundefinedSet of objects which describe validators that evaluate on each field value (or one of its dependencies) change. A field is valid when all of the validator functions return true (or has no validators at all). The order of validators corresponds to the order that field.errors appear. More info
contextstring arrayundefinedArray of context ids (which represent app data) that the current field is depended on at any time of the field's evaluation. More info
requiredbooleanfalseFlag that reflects if the field is required. Can be dynamically changed by defining requireTerm. More info
excludedbooleanfalseFlag that reflects if the field is excluded. Can be dynamically changed by defining excludeTerm. More info
disabledbooleanfalseFlag that reflects if the field is disabled. Can be dynamically changed by defining disableTerm. More info
dirtybooleanfalseFlag that reflects if the field is dirty. More info
emptybooleanfalseFlag that reflects if the field is empty. It's a result of isEmpty hook. More info
invalidbooleanfalseFlag that reflects if the field is invalid. Invalid is a result of both field's required and validators. More info
errorsobject array[]Object array that reflects the field's errors. It's a result of both required and validators. More info
excludeTermobjectundefinedExclude a field under certain terms (i.e dynamic change of excluded flag). Object describes a logical regular expression, which evaluated on init and on each field value (or one of its dependencies) change, and its result is set to field's excluded flag. More info
disableTermobjectundefinedDisable a field under certain terms (i.e dynamic change of disabled flag). Object describes a logical regular expression, which evaluated on init and on each field value (or one of its dependencies) change, and its result is set to field's disables flag. More info
requireTermobjectundefinedRequire a field under certain terms (i.e dynamic change of required flag). Object describes a logical regular expression, which evaluated on init and on each field value (or one of its dependencies) change, and its result is set to field's required flag. More info

Example

const model = {
  // ...
  fields: {
    firstName: {
      path: 'firstName',
      label: 'First Name',
      description: 'Your full name as appears in your passport',
      component: {
        name: 'InputText',
        state: {
          placeholder: 'Enter First Name',
        }
      },
      required: true,
      validators: [{
        name: 'minLength',
        args: { value: 2 },
      }],
    },
    hobbies: {
      path: 'hobbies',
      label: 'Hobbies',
      description: 'Activities you enjoy during your free time',
      component: {
        name: 'Checkboxes',
        state: {
          items: [{
            label: 'Dance',
            value: 'DANCE'
          }, {
            label: 'Football',
            value: 'FOOTBALL'
          }, {
            label: 'Baseball',
            value: 'BASEBALL'
          }]
        }
      },
    },
  },
};
← DataPath →
  • Field key
  • Field value
  • Example
cofi
Copyright © 2021 Verizon Media
DOCS
IntroductionForm ClassReact FormReact ComponentsReact Layout
DEMOS
React FormReact ComponentsReact Layout
CONTRIBUTING
Code Of ConductContributing GuideContributorsUsers
CHANNELS
StarGitHubStack OverflowMediumVideos