0.9.72 • Published 5 years ago

immutable-core-model-form v0.9.72

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

immutable-core-model-form

Immutable Core Model Form provides a Class for defining forms for Immutable Core Models.

Immutable Core Model Form instances are constructed with defaults based on the schema of the Immutable Core Model the form is for. These defaults can then be overriden to customize the form.

Native async/await

Immutable Core Model Form requires Node.js v7.6.0 or greater with native async/await support.

Creating a Form From a Model

const ImmutableCoreModel = require('immutable-core-model')
const ImmutableCoreModelForm = require('immutable-core-model-form')

var addressModel = new ImmutableCoreModel({
    name: 'address',
    properties: {
        addressCountry: {
            default: 'US',
            title: 'Country',
            type: 'string',
        },
        addressLocality: {
            title: 'City',
            type: 'string',
        },
        addressRegion: {
            enum: ['AL', 'AK', 'AZ'],
            title: 'State',
            type: 'string',
        },
        firstName: {
            type: 'string',
        },
        lastName: {
            type: 'string',
        },
        postalCode: {
            errors: {
                pattern: '5 digit ZIP code required',
            },
            pattern: '^\\d{5}$',
            title: 'ZIP Code',
            type: 'string',
        },
        streetAddress: {
            type: 'string',
        },
    },
    required: [
        'addressCountry',
        'addressLocality',
        'addressRegion',
        'firstName',
        'lastName',
        'postalCode',
        'streetAddress',
    ],
})

var addressForm = new ImmutableCoreModelForm({
    fields: [
        ['firstName', 'lastName'],
        'streetAddress',
        [
            {
                property: 'addressLocality',
                unit: '3-5',
            },
            {
                property: 'addressRegion',
                unit: '1-5',
            },
            {
                property: 'postalCode',
                unit: '1-5',
            },
        ],
        {
            property: 'addressCountry',
            inputType: 'hidden',
        },
    ],
    model: fooModel,
})

In this example an address model is created with property names based on Schema.org Postal Address.

The enum, default, description, title and type from the JSON Schema for the model will be used to populate default form options.

Fields

The fields array contains field specifications in the order that they will be presented in the from.

A field can be specified as either the name of the model property that the field maps to or an object that contains the property along with other configuration options.

A field group can be specified by providing an array value for the field. This array must consist of either string property names or object field specifications.

Creating a From Without a Model

var registerForm = new ImmutableCoreModelForm({
    fields: [
        {
            inputType: 'text',
            name: 'firstName'
            placeholder: 'First Name',
            required: true,
        },
        {
            inputType: 'text',
            name: 'lastName'
            placeholder: 'Last Name',
            required: true,
        },
        {
            inputType: 'text',
            name: 'email'
            placeholder: 'Email',
            required: true,
        },
        {
            inputType: 'password',
            name: 'password'
            placeholder: 'Password',
            required: true,
        },
    ],
    method: 'post',
    submit: {
        title: 'Register',
    },
})

Form Properties

namedescription
actionaction property for form element - url form will submit to
fieldslist of form fields may be field or sub-list of fields
idid property for form element
enctypeenctype property for form element
methodmethod property for form element
submitobject with submit properties - if false will not render
submit.titletext value for submit button

Field Types

name
checkbox
color
hidden
password
select
text

Field Properties

namedescription
descriptiondescription that will be shown in help tooltip
idinput id property, needed to link label to input
inputSizesize property for input
labeltext that will be shown as label - false for no label
nameinput name property
patternregex pattern for validating input value
placeholderplaceholder to display in input - false for none
readonlymake input read only
requiredmake input required

Units

The unit option is used by the default Immutable App form view to set the grid units that a field in a field group occupies. Immutable App uses Pure CSS Grids.

If the unit option is not specified then it will be defaulted to 1-n where n is the number of fields in the field group.

Creating a form instance from a record

addressForm.newInstance({record: record})

When the newInstance method is called with a model instance a form instance with values populated from the existing model will be returned.

Creating a form instance from input and errors

addressForm.newInstance({
    errors: errors,
    input: input,
})

If form submission results in errors then newInstance can be called with the form input and errors to create a new form instance with correct values and error messages populated.

0.9.72

5 years ago

0.9.71

5 years ago

0.9.70

5 years ago

0.9.69

6 years ago

0.9.68

6 years ago

0.9.67

6 years ago

0.9.66

6 years ago

0.9.65

6 years ago

0.9.64

6 years ago

0.9.63

6 years ago

0.9.62

6 years ago

0.9.61

6 years ago

0.9.60

6 years ago

0.9.59

6 years ago

0.9.58

6 years ago

0.9.57

6 years ago

0.9.56

6 years ago

0.9.55

6 years ago

0.9.54

6 years ago

0.9.53

6 years ago

0.9.52

6 years ago

0.9.51

6 years ago

0.9.50

6 years ago

0.9.49

6 years ago

0.9.48

6 years ago

0.9.47

6 years ago

0.9.46

6 years ago

0.9.45

6 years ago

0.9.44

6 years ago

0.9.43

6 years ago

0.9.42

7 years ago

0.9.41

7 years ago

0.9.40

7 years ago

0.9.39

7 years ago

0.9.38

7 years ago

0.9.37

7 years ago

0.9.36

7 years ago

0.9.35

7 years ago

0.9.34

7 years ago

0.9.33

7 years ago

0.9.32

7 years ago

0.9.31

7 years ago

0.9.30

7 years ago

0.9.29

7 years ago

0.9.28

7 years ago

0.9.27

7 years ago

0.9.26

7 years ago

0.9.25

7 years ago

0.9.24

7 years ago

0.9.23

7 years ago

0.9.22

7 years ago

0.9.21

7 years ago

0.9.20

7 years ago

0.9.19

7 years ago

0.9.18

7 years ago

0.9.17

7 years ago

0.9.16

7 years ago

0.9.15

7 years ago

0.9.14

7 years ago

0.9.13

7 years ago

0.9.12

7 years ago

0.9.11

7 years ago

0.9.10

7 years ago

0.9.7

7 years ago

0.9.6

7 years ago

0.9.5

7 years ago

0.9.4

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.21

7 years ago

0.8.20

7 years ago

0.8.19

7 years ago

0.8.18

7 years ago

0.8.17

7 years ago

0.8.16

7 years ago

0.8.15

7 years ago

0.8.14

7 years ago

0.8.13

7 years ago

0.8.12

7 years ago

0.8.11

7 years ago

0.8.10

7 years ago

0.8.9

7 years ago

0.8.8

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.7.48

7 years ago

0.7.47

7 years ago

0.7.46

7 years ago

0.7.45

7 years ago

0.7.44

7 years ago

0.7.43

7 years ago

0.7.42

7 years ago

0.7.41

7 years ago

0.7.40

7 years ago

0.7.39

7 years ago

0.7.38

7 years ago

0.7.37

7 years ago

0.7.36

7 years ago

0.7.35

7 years ago

0.7.34

7 years ago

0.7.33

7 years ago

0.7.32

7 years ago

0.7.31

7 years ago

0.7.30

7 years ago

0.7.29

7 years ago

0.7.28

7 years ago

0.7.27

7 years ago

0.7.26

7 years ago

0.7.25

7 years ago

0.7.24

7 years ago

0.7.23

7 years ago

0.7.22

7 years ago

0.7.21

7 years ago

0.7.20

7 years ago

0.7.19

7 years ago

0.7.18

7 years ago

0.7.17

7 years ago

0.7.16

7 years ago

0.7.15

7 years ago

0.7.14

7 years ago

0.7.13

7 years ago

0.7.12

7 years ago

0.7.11

7 years ago

0.7.10

7 years ago

0.7.9

7 years ago

0.7.8

7 years ago

0.7.7

7 years ago

0.7.6

7 years ago

0.7.5

7 years ago

0.7.4

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.50

7 years ago

0.6.49

7 years ago

0.6.48

7 years ago

0.6.47

7 years ago

0.6.46

7 years ago

0.6.45

7 years ago

0.6.44

7 years ago

0.6.43

7 years ago

0.6.42

7 years ago

0.6.41

7 years ago

0.6.40

7 years ago

0.6.39

7 years ago

0.6.38

7 years ago

0.6.37

7 years ago

0.6.36

7 years ago

0.6.35

7 years ago

0.6.34

7 years ago

0.6.33

7 years ago

0.6.32

7 years ago

0.6.31

7 years ago

0.6.30

7 years ago

0.6.29

7 years ago

0.6.28

7 years ago

0.6.27

7 years ago

0.6.26

7 years ago

0.6.25

7 years ago

0.6.24

7 years ago

0.6.23

7 years ago

0.6.22

7 years ago

0.6.21

7 years ago

0.6.20

7 years ago

0.6.19

7 years ago

0.6.18

7 years ago

0.6.17

7 years ago

0.6.16

7 years ago

0.6.15

7 years ago

0.6.14

7 years ago

0.6.13

7 years ago

0.6.12

7 years ago

0.6.11

7 years ago

0.6.10

7 years ago

0.6.9

7 years ago

0.6.8

7 years ago

0.6.7

7 years ago

0.6.6

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.29

7 years ago

0.4.28

7 years ago

0.4.27

7 years ago

0.4.26

7 years ago

0.4.25

7 years ago

0.4.24

7 years ago

0.4.23

7 years ago

0.4.22

7 years ago

0.4.21

7 years ago

0.4.20

7 years ago

0.4.19

7 years ago

0.4.18

7 years ago

0.4.17

7 years ago

0.4.16

7 years ago

0.4.15

7 years ago

0.4.14

7 years ago

0.4.13

7 years ago

0.4.12

7 years ago

0.4.11

7 years ago

0.4.10

7 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago