Skip to content

List of options for built in classes

Roberto Prevato edited this page Jan 1, 2018 · 12 revisions

This page lists the available options for all built-in classes. Described options should be used when instantiating a DataEntry and are handled by dependent classes. For example, the constraintRules is described below the DomBinder class, and it can be passed as option when instantiating a DataEntry, configured to use this kind of binder.

Core classes

DataEntry

schema

  • type: object
  • default: undefined Object describing the schema of the fields validated by the dataentry. Each key of this object (property) must match the name of a field. In the example below, for example, three fields are defined: name, year, policy-read.
const dataentry = new DataEntry({
  schema: {
    name: {
      validation: ["required"],
      format: ["cleanSpaces"]
    },
    year: {
      validation: ["required", { name: "integer", params: [{ min: 1900, max: 2015 }] }]
    },
    "policy-read": {
      validation: ["mustCheck"]
    }
  }

The values of these properties can be:

  • an array of validation rules:
    "foo": ["required"]
  • an object, to have more control
    "foo": {
      validation: ["required"],
      format: ["trim"]
    },
    "ufo": {
      validation: ["required"],
      format: ["zero-fill"],
      preformat: ["zero-unfill"], // NB: preformat is only used by DomBinder class
      constraint: "digits"  // NB: constraint is only used by DomBinder class
    }
  • a function returning an array of values
    "foo": function () {
       // function called in the context of the dataentry, or instance of dataentry
       if (someCondition) 
          return ["required"];
       // otherwise...
       return ["none"];
    } 

context

If specified, it is used to read and write values by built-in DomHarvester and ContextHarvester.

  • type: object
  • default: undefined

element

An element for the dataentry is required only by built-in DOM classes: DomDecorator, DomHarvester, DomBinder.

  • type: HTMLElement
  • default: undefined

triggersDelay

If specified as a number, it is used to set a timeout with setTimeout, when triggering validation between fields.

  • type: number
  • default: undefined

Validator

rules

Additional validation rules to be defined for an instance of Validator (in addition to global validation rules defined in Validator.Rules).

  • type: object
  • default: undefined

Formatter

formatRules

Additional format rules to be defined for an instance of Formatter (in addition to global formatting rules defined in Formatter.Rules).

  • type: object
  • default: undefined

DOM classes

DomHarvester

sourceObject

Object used to read and write values of fields, by names specified in dataentry schema. If a context is specified for the dataentry, and sourceObject is not specified, the context is used instead to read and write values.

  • type: object
  • default: undefined

DomDecorator

markStyle

The style to mark fields in invalid state, or to add information to fields. By default, tooltips are used.

  • type: string
  • default: "tooltips"

DomBinder

useImplicitConstraints

Whether to enable implicit constraints (application of constraints rules by matching name of validation rule).

  • type: bool
  • default: true

useImplicitFormat

Whether to enable implicit formatting (application of formatting rules by matching name of validation rule).

  • type: bool
  • default: true

constraintRules

Additional constraint rules to be defined for an instance of DomBinder.

  • type: object
  • default: undefined

events

Additional event handlers for an instance of DomBinder. Event handlers are attached to the dataentry element, and removed when the dataentry dispose method is called.

  • type: object
  • default: undefined

Example:

events: {
  "change #foo": function (e) {},
  "focus .something": function (e) {}
}

validationEvent

Let specify which event should fire validation for the dataentry. If not specified, the global setting DomBinder.validationEvent is used ("blur"). If a validationEvent is specified for a field, it overrides these two settings.

  • type: string
  • default: "blur"

Example: specifying a validation event for a field

schema: {
  foo: ["required"],
  ufo: { 
    validation: ["none"], 
    validationEvent: "keyup" 
  }
},

Example: specifying multiple events to fire validation for a field:

schema: {
  foo: ["required"],
  ufo: { 
    validation: ["none"], 
    validationEvent: "blur, custom" // fire validation on event "blur" and "custom"
  }
},

By design, formatting of values is applied after successful validation, and since validation may require AJAX requests, it's highly recommended to use the default settings (firing validation on field blur), and avoid validation and formatting while the user is typing (i.e. firing validation on a keyboard event).


Context classes

ContextHarvester

sourceObject

Object used to read and write values of fields, by names specified in dataentry schema. If a context is specified for the dataentry, and sourceObject is not specified, the context is used instead to read and write values.

  • type: object
  • default: undefined

ContextDecorator

validationTarget

Object populated with information about the state of fields, by their name. If not specified, a plain object is instantiated automatically.

  • type: object
  • default: undefined