-
Notifications
You must be signed in to change notification settings - Fork 0
List of options for built in classes
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.
- 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"];
}
If specified, it is used to read and write values by built-in DomHarvester
and ContextHarvester
.
- type: object
- default: undefined
An element
for the dataentry is required only by built-in DOM classes: DomDecorator
, DomHarvester
, DomBinder
.
- type: HTMLElement
- default: undefined
If specified as a number, it is used to set a timeout with setTimeout
, when triggering validation between fields.
- type: number
- default: undefined
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
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
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
The style to mark fields in invalid state, or to add information to fields. By default, tooltips are used.
- type: string
- default: "tooltips"
Whether to enable implicit constraints (application of constraints rules by matching name of validation rule).
- type: bool
- default: true
Whether to enable implicit formatting (application of formatting rules by matching name of validation rule).
- type: bool
- default: true
Additional constraint rules to be defined for an instance of DomBinder.
- type: object
- default: undefined
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) {}
}
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).
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
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