0.37.2 • Published 5 years ago

@8base/forms v0.37.2

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

8base Forms

8base Forms is a thin React wrapper for React Final Forms to easy implement forms for 8base API entities.

API

Table of Contents

Field

Extends React.Component

Field wrapper based on Field from the react-final-form. This component accepts FieldProps and other props for easy implementation with the 8base API.

Properties

  • fieldSchema FieldSchema? The 8base API field schema.
  • name string? The name of field, based on the 8base API table schema.

FieldArray

Extends React.Component

FieldArray wrapper based on FieldArray from the react-final-form-arrays. It accepts FieldArrayProps as a prop.

Fieldset

Extends React.Component

Fieldset passes relation table schema to the children fields.

Properties

  • tableSchema TableSchema? The 8base API table schema.
  • tableSchemaName string? The name of the 8base API table schema. This prop only works if SchemaContext is provided.

Form

Extends React.Component

Form wrapper based on Form from the react-final-form. This component accepts FormProps and other props for easy implementation with the 8base API.

Properties

  • tableSchema TableSchema? The 8base API table schema.
  • tableSchemaName string? The name of the 8base API table schema. This prop only works if SchemaContext is provided.

Examples

Basic Form

import React from 'react';
import { render } from 'react-dom';
import { Form, Field } from '@8base/forms';

const TABLE_SCHEMA = {
  name: 'client',
  displayName: 'Client',
  isSystem: false,
  fields: [{
    name: 'firstName',
    displayName: 'First Name',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: 'Vladimir',
    relation: null,
  }, {
    name: 'lastName',
    displayName: 'Last Name',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: 'Putin',
    relation: null,
  }, {
    name: 'age',
    displayName: 'Age',
    description: null,
    fieldType: 'NUMBER',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: null,
    relation: null,
  }],
};

render(
  <Form type="CREATE" onSubmit={onSubmit}>
    {
      ({ handleSubmit }) => (
        <form onSubmit={ handleSubmit }>
          <Field name="firstName" component="input" />
          <Field name="lastName" component="input" />
          <Field name="age" component="input" />
          <button type="submit">Create Client</button>
        </form>
      )
    }
  </Form>
, document.getElementById('root'));

Form with FieldArray

import React from 'react';
import { render } from 'react-dom';
import { Form, Field, FieldArray } from '@8base/forms';

const TABLE_SCHEMA = {
  name: 'client',
  displayName: 'Client',
  isSystem: false,
  fields: [{
    name: 'firstName',
    displayName: 'First Name',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: 'Vladimir',
    relation: null,
  }, {
    name: 'lastName',
    displayName: 'Last Name',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: 'Putin',
    relation: null,
  }, {
    name: 'age',
    displayName: 'Age',
    description: null,
    fieldType: 'NUMBER',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: null,
    relation: null,
  }, {
    name: 'fieldArray',
    displayName: 'FieldArray',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: true,
    isRequired: true,
    isUnique: false,
    defaultValue: null,
    relation: null,
  }],
};

render(
  <Form type="CREATE" onSubmit={onSubmit}>
    {
      ({ handleSubmit }) => (
        <form onSubmit={ handleSubmit }>
          <Field name="firstName" component="input" />
          <Field name="lastName" component="input" />
          <Field name="age" component="input" />
          <FieldArray name="fieldArray">
            {
              React.Children.toArray(({ fields }) => (
                <React.Fragment>
                  {
                    fields.map((name, index) => (
                      <React.Fragment>
                        <Field key={ name } name={ name } component="input" />
                        <button onClick={ () => fields.remove(index) }>Remove</button>
                      </React.Fragment>
                    ))
                  }
                  <button onClick={ () => fields.push('New Field Array Item') }>Add</button>
                </React.Fragment>
              ))
            }
          </FieldArray>
          <button type="submit">Create Client</button>
        </form>
      )
    }
  </Form>
, document.getElementById('root'));

Multiple Forms with TableSchemaProvider

import React from 'react';
import { render } from 'react-dom';
import { Form, Field } from '@8base/forms';
import { TableSchemaProvider } from '@8base/table-schema-provider';

const SCHEMA = [{
  name: 'client',
  displayName: 'Client',
  isSystem: false,
  fields: [{
    name: 'firstName',
    displayName: 'First Name',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: 'Vladimir',
    relation: null,
  }, {
    name: 'lastName',
    displayName: 'Last Name',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: 'Putin',
    relation: null,
  }, {
    name: 'age',
    displayName: 'Age',
    description: null,
    fieldType: 'NUMBER',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: null,
    relation: null,
  }],
}, {
  name: 'order',
  displayName: 'Order',
  isSystem: false,
  fields: [{
    name: 'name',
    displayName: 'name',
    description: null,
    fieldType: 'TEXT',
    fieldTypeAttributes: {
      format: 'UNFORMATTED',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: null,
    relation: null,
  }, {
    name: 'deliveryDate',
    displayName: 'Delivery Date',
    description: null,
    fieldType: 'DATE',
    fieldTypeAttributes: {
      format: 'DATE',
      fieldSize: 100,
    },
    isList: false,
    isRequired: true,
    isUnique: false,
    defaultValue: null,
    relation: null,
  }],
}];

render(
  <TableSchemaProvider schema={SCHEMA}>
    <Form type="CREATE" tableSchemaName="client" onSubmit={ onSubmitClient }>
      {
        ({ handleSubmit }) => (
          <form onSubmit={ handleSubmit }>
            <Field name="firstName" component="input" />
            <Field name="lastName" component="input" />
            <Field name="age" component="input" />
            <button type="submit">Create Client</button>
          </form>
        )
      }
    </Form>
    <Form type="CREATE" tableSchemaName="order" onSubmit={onSubmitOrder}>
      {
        ({ handleSubmit }) => (
          <form onSubmit={ handleSubmit }>
            <Field name="name" component="input" />
            <Field name="deliveryDate" component="input" />
            <button type="submit">Create Order</button>
          </form>
        )
      }
    </Form>
  </TableSchemaProvider>
, document.getElementById('root'));

Complex form

import React from 'react';
import { render } from 'react-dom';
import { Form, Field } from '@8base/forms';
import { TableSchemaProvider } from '@8base/table-schema-provider';

const SCHEMA = [{
  id: 'TABLE_SCHEMA_ID',
  name: 'tableSchema',
  displayName: 'Table Schema',
  isSystem: false,
  fields: [
    {
      name: 'scalar',
      displayName: 'Scalar',
      description: null,
      fieldType: 'TEXT',
      fieldTypeAttributes: {
        format: 'UNFORMATTED',
        fieldSize: 100,
      },
      isList: false,
      isRequired: false,
      isUnique: false,
      defaultValue: 'Scalar Default Value',
      relation: null,
    },
    {
      name: 'scalarList',
      displayName: 'Scalar List',
      description: null,
      fieldType: 'TEXT',
      fieldTypeAttributes: {
        format: 'UNFORMATTED',
        fieldSize: 100,
      },
      isList: true,
      isRequired: false,
      isUnique: false,
      defaultValue: 'Scalar List Default Value 1',
      relation: null,
    },
    {
      name: 'relation',
      displayName: 'Relation',
      description: null,
      fieldType: 'RELATION',
      fieldTypeAttributes: null,
      isList: false,
      isRequired: false,
      isUnique: null,
      defaultValue: null,
      relation: {
        id: 'RELATION_FIELD_ID_1',
        relationTableName: 'RELATION_TABLE_NAME_1',
        relationFieldName: 'aid',
        refTable: {
          id: 'RELATION_TABLE_SCHEMA_ID',
        },
        refFieldIsList: false,
        refFieldIsRequired: true,
      },
    },
    {
      name: 'relationList',
      displayName: 'RelationList',
      description: null,
      fieldType: 'RELATION',
      fieldTypeAttributes: null,
      isList: true,
      isRequired: false,
      isUnique: null,
      defaultValue: null,
      relation: {
        id: 'RELATION_FIELD_ID_2',
        relationTableName: 'RELATION_TABLE_NAME_2',
        relationFieldName: 'aid',
        refTable: {
          id: 'RELATION_TABLE_SCHEMA_ID',
        },
        refFieldIsList: false,
        refFieldIsRequired: true,
      },
    },
  ],
}, {
  id: 'RELATION_TABLE_SCHEMA_ID',
  name: 'relationTableSchema',
  displayName: 'Relation Table Schema',
  isSystem: false,
  fields: [
    {
      name: 'scalar',
      displayName: 'Scalar',
      description: null,
      fieldType: 'TEXT',
      fieldTypeAttributes: {
        format: 'UNFORMATTED',
        fieldSize: 100,
      },
      isList: false,
      isRequired: false,
      isUnique: false,
      defaultValue: 'Scalar Default Value',
      relation: null,
    },
    {
      name: 'scalarList',
      displayName: 'Scalar List',
      description: null,
      fieldType: 'TEXT',
      fieldTypeAttributes: {
        format: 'UNFORMATTED',
        fieldSize: 100,
      },
      isList: true,
      isRequired: false,
      isUnique: false,
      defaultValue: 'Scalar List Default Value 1',
      relation: null,
    },
    {
      name: 'relation',
      displayName: 'Relation',
      description: null,
      fieldType: 'RELATION',
      fieldTypeAttributes: null,
      isList: false,
      isRequired: false,
      isUnique: null,
      defaultValue: null,
      relation: {
        id: 'RELATION_FIELD_ID_3',
        relationTableName: 'RELATION_TABLE_NAME_1',
        relationFieldName: 'aid',
        refTable: {
          id: 'TABLE_SCHEMA_ID',
        },
        refFieldIsList: false,
        refFieldIsRequired: true,
      },
    },
    {
      name: 'relationList',
      displayName: 'RelationList',
      description: null,
      fieldType: 'RELATION',
      fieldTypeAttributes: null,
      isList: true,
      isRequired: false,
      isUnique: null,
      defaultValue: null,
      relation: {
        id: 'RELATION_FIELD_ID_4',
        relationTableName: 'RELATION_TABLE_NAME_2',
        relationFieldName: 'aid',
        refTable: {
          id: 'TABLE_SCHEMA_ID',
        },
        refFieldIsList: false,
        refFieldIsRequired: true,
      },
    },
  ],
}];

const INITIAL_VALUES = {
  scalar: 'Scalar Value',
  scalarList: [
    'Scalar List Value',
  ],
  relation: {
    scalar: 'Relation Scalar Value',
  },
  relationList: [{
    scalar: 'Relation List Scalar Value',
  }],
};

render(
  <TableSchemaProvider value={ SCHEMA }>
    <Form type="CREATE" tableSchemaName="tableSchema" initialValues={ INITIAL_VALUES } onSubmit={ onSubmitForm }>
      {
        ({ handleSubmit }) => (
          <form onSubmit={ handleSubmit }>
            <Field name="scalar" component="input" />
            <FieldArray name="scalarList">
              {
                ({ fields }) => (
                  fields.map((name) => (
                    <Field key={ name } name={ name } component="input" />
                  ))
                )
              }
            </FieldArray>
            <Fieldset tableSchemaName="relationTableSchema">
              <Field name="relation.scalar" component="input" />
            </Fieldset>
            <FieldArray name="relationList">
              {
                ({ fields }) => (
                  fields.map((name) => (
                    <Fieldset key={ name } tableSchemaName="relationTableSchema">
                      <Field name={ `${name}.scalar` } component="input" />
                    </Fieldset>
                  ))
                )
              }
            </FieldArray>
          </form>
        )
      }
    </Form>
  </TableSchemaProvider>
, document.getElementById('root'));
0.37.2

5 years ago

0.37.1

5 years ago

0.37.0

5 years ago

0.36.6

5 years ago

0.36.5

5 years ago

0.36.4

5 years ago

0.36.3

5 years ago

0.36.2

5 years ago

0.36.1

5 years ago

0.36.0

5 years ago

0.35.1

5 years ago

0.35.0

5 years ago

0.34.0

5 years ago

0.33.1

5 years ago

0.33.0

5 years ago

0.32.3

5 years ago

0.32.2

5 years ago

0.32.1

5 years ago

0.32.0

5 years ago

0.31.2

5 years ago

0.31.1

5 years ago

0.31.0

5 years ago

0.30.0

5 years ago

0.29.2

5 years ago

0.29.1

5 years ago

0.29.0

5 years ago

0.28.5

5 years ago

0.28.4

5 years ago

0.28.3

5 years ago

0.28.2

5 years ago

0.28.1

5 years ago

0.28.0

5 years ago

0.27.1

5 years ago

0.27.0

5 years ago

0.26.0

5 years ago

0.25.1

5 years ago

0.25.0

5 years ago

0.24.0

5 years ago

0.23.1

5 years ago

0.23.0

5 years ago

0.22.0

5 years ago

0.21.4

5 years ago

0.21.3

5 years ago

0.21.2

5 years ago

0.21.1

5 years ago

0.21.0

5 years ago

0.20.4

5 years ago

0.20.3

5 years ago

0.20.2

5 years ago

0.20.1

5 years ago

0.20.0

5 years ago

0.19.6

5 years ago

0.19.5

5 years ago

0.19.4

5 years ago

0.19.3

5 years ago

0.19.2

5 years ago

0.19.1

5 years ago

0.19.0

5 years ago

0.18.7

5 years ago

0.18.6

5 years ago

0.18.5

5 years ago

0.18.4

5 years ago

0.18.3

5 years ago

0.18.2

5 years ago

0.18.1

5 years ago

0.18.0

5 years ago

0.17.2

5 years ago

0.17.1

5 years ago

0.17.0

5 years ago

0.16.10

5 years ago

0.16.9

5 years ago

0.16.8

5 years ago

0.16.7

5 years ago

0.16.6

5 years ago

0.16.5

5 years ago

0.16.4

5 years ago

0.16.3

5 years ago

0.16.2

5 years ago

0.16.1

5 years ago

0.16.0

5 years ago

0.15.4

5 years ago

0.15.3

5 years ago

0.15.2

5 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.14.4

5 years ago

0.14.3

5 years ago

0.14.2

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.3

5 years ago

0.11.2

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.5

5 years ago

0.10.4

5 years ago

0.10.3

5 years ago

0.10.2

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

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.12

5 years ago

0.6.11

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

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.10

5 years ago

0.5.9

5 years ago

0.5.8

5 years ago

0.5.7

5 years ago

0.5.6

5 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.27

6 years ago

0.4.26

6 years ago

0.4.25

6 years ago

0.4.24

6 years ago

0.4.23

6 years ago

0.4.22

6 years ago

0.4.21

6 years ago

0.4.20

6 years ago

0.4.19

6 years ago

0.4.18

6 years ago

0.4.16

6 years ago

0.4.15

6 years ago

0.4.14

6 years ago

0.4.13

6 years ago

0.4.11

6 years ago

0.4.10

6 years ago

0.4.9

6 years ago

0.4.8

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.1

6 years ago