1.8.5 • Published 5 years ago

doiforms v1.8.5

Weekly downloads
2
License
ISC
Repository
-
Last release
5 years ago

Introduction

This is a javascript forms package for the DOI LE Portal.

The intention is that this package provides the high level logic for building your own forms.

To style the forms and provide extra bells and whistles implement a template form or use the existing Bootstrap 3 Form Templates.

Getting Started

  1. Installation process

    Install from npm using "npm i doiforms"

    to install the template form library run "npm i bootstrap3formtemplates"

  2. Software dependencies

This library is built with React 16.8.3.

  1. Usage

Basic usage looks something like this:

import { FormTemplate } from "bootstrap3formtemplates";
import {
  DOIFormComponent,
  EnumFieldType,
  IFieldState,
} from "doiforms";
import * as React from "react";

export default function MyForm(): JSX.Element{
    const field = {
      DisplayName: "Your Name",
      Id: "name",
      Name: "name",
      Order: 0,
      Required: true,
      Type: EnumFieldType.text };
    const submit = {
          DisplayName: "Submit",
          Id: "submitb",
          Name: "submitb",
          Order: 1,
          Required: true,
          Type: EnumFieldType.submit
        };
    return <DOIFormComponent        
        ErrorHandler={(ErrorMessage?: string, Stack?: string) => <h1>{ErrorMessage || "Error"}</h1><p>{Stack}</p>}
        Fields={[field,submit]}
        FormTemplate={FormTemplate}
        RedirectURL={"https://localhost"}
        SubmitAction={() => {
          return new Promise<void>(
            (resolve: () => void, reject: (reason: any) => void) => {
              resolve();
            });
        }} />;
}

Buttons may be added as input fields or added in the optional Header or Footer properties.

The FormTemplate property is a function implemented using the following signatures:

interface IDOIFormAction {
    Action: EnumFormAction;
    Update?: IDOIFormState;
}
type FormActionFunc = (action: IDOIFormAction) => void;
interface ITemplateFormProps {
    Buttons: IButton[];
    ErrorHandler: ErrorHandlerFunc;
    FieldStates: IFieldState[];
    Footer?: JSX.Element;
    HandleSubmit: () => void;
    HandleReset: () => void;
    Header?: JSX.Element;
    IsError?: boolean;
    SendMessage: FormActionFunc;
    Styles: React.CSSProperties;
    SystemErrorMessage?: string;
}
type TemplateFormFunc = (props: ITemplateFormProps) => JSX.Element;

Template forms send messages to doiforms using the SendMessage property. Messages include:

enum EnumFormAction {
    NoOp = 0,
    Submit = 1,
    Reset = 2,
    Update = 3,
    HandleError = 4
}
1.8.5

5 years ago

1.8.4

5 years ago

1.8.3

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.21

5 years ago

1.2.20

5 years ago

1.2.19

5 years ago

1.2.18

5 years ago

1.2.17

5 years ago

1.2.16

5 years ago

1.2.15

5 years ago

1.2.14

5 years ago

1.2.13

5 years ago

1.2.12

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.5

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago