ValidationManager is the central object for using this system. It is where you describe the shape of your inputs and their validation rules. Once setup, it keeps a list of ValueHost objects that represent the elements of your model or form, even if they don't need validation.

Configs are interfaces you use with plain objects to fashion them into ValidationManager's configuration. ValueHostConfig describes a ValueHost. InputValueHostConfig describes an InputValueHost (which supports validation). An InputValueHost takes ValidatorConfigs to fashion its list of Validators. An Validator takes various ConditionConfigs to fashion the specific validation rule.

ValidationManager's constructor takes a single parameter, but its a potent one: it's Configuration object (type=ValidationManagerConfig). By the time you create the ValidationManager, you have provided all of those configs to the Configuration object. It also supplies the ValidationServices object, state data, and callbacks. See the constructor's documentation for a sample of the Configuration object.

We recommend using your business logic to host the validation rules. For that, you will need code that translates those rules into ValidatorConfigs. Try to keep validation rules separate from your UI's code.

All Configs are considered immutable. If you need to make a change, you can create a new instance of ValidationManager, or call its addValueHost, addOrUpdateValueHost, or discardValueHost methods to keep the existing instance.

ValidationManager's job is:

  • Create and retain all ValueHosts.
  • Provide access to all ValueHosts with its getValueHost() function.
  • Retain InstanceState objects that reflects the states of all ValueHost instances. This system can operate in a stateless way, so long as you keep these objects and pass them back via the Configuration object. Its OnInstanceStateChanged and OnValueHostInstanceStateChanged properties are callbacks provide the latest InstanceState objects to you.
  • Execute validation on demand to the consuming system, going through all eligible InputValueHosts.
  • Report a list of Issues Found for an individual UI element.
  • Report a list of Issues Found for the entire system for a UI element often known as "Validation Summary".

Notice that this class does not know anything about consuming system. As a result depends on the consuming system to transfer values between the UI and the ValueHosts. Auxillary Jivs libraries may handle this.

Type Parameters

Hierarchy (view full)

Implements

Constructors

Accessors

  • get isValid(): boolean
  • When true, the current state of validation does not know of any errors. However, there are other factors to consider: there may be warning issues found (in IssuesFound), an async validator is still running, validator evaluated as Undetermined. So check

    Returns boolean

    Link

    doNotSave|doNotSave as the ultimate guide to saving. When false, there is at least one validation error.

Methods

  • Easier way to add or modify a ValueHostConfig than using addValueHost(), addOrUpdateValueHost(), or addOrMergeValueHost(). It returns an object whose methods allow adding ValueHosts and their validators. Upon calling its apply() method, your changes will be applied through the addOrMergeValueHost() function.

    let vm = new ValidationManager(builder);
    // later when you need to modify vm:
    let modifier = vm.startModifying();
    // supply changes to the ValueHostConfigs
    modifier.input('Field3').regExp(null, { enabled: false }); // let's disable the existing validator
    // merge those changes into the ValidationManager
    modifier.apply(); // consider modifier disposed at this point

    Returns ValidationManagerConfigModifier

  • ValueHosts that validate should try to fire onValidationStateChanged, even though they also fire onValueHostValidationStateChanged. This allows systems that observe validation changes at the validationManager level to know. This function is optionally debounced with a delay in ms coming from ValidationManagerConfig.notifyValidationStateChangedDelay

    Parameters

    • validationState: null | ValidationState
    • Optional options: ValidateOptions
    • Optional force: boolean

      when true, override the debouncer and execute immediately.

    Returns void

  • When Business Logic gathers data from the UI, it runs its own final validation. If its own business rule has been violated, it should be passed here where it becomes exposed to the Validation Summary (getIssuesFound) and optionally for an individual ValueHostName, by specifying that valueHostName in associatedValueHostName. Each time its called, all previous business logic errors are abandoned. Internally, a BusinessLogicErrorsValueHost is added to the list of ValueHosts to hold any error that lacks an associatedValueHostName.

    Parameters

    • errors: null | BusinessLogicError[]

      A list of business logic errors to show or null to indicate no errors.

    • Optional options: ValidateOptions

      Only considers the skipCallback option.

    Returns boolean

    When true, the validation snapshot has changed.

  • Lists all issues found (error messages and supporting info) for a single InputValueHost so the input field/element can show error messages and adjust its appearance.

    Parameters

    • valueHostName: string

    Returns null | IssueFound[]

    An array of 0 or more details of issues found. When 0, there are no issues and the data is valid. If there are issues, when all have severity = warning, the data is also valid. Anything else means invalid data. Each contains:

    • name - The name for the ValueHost that contains this error. Use to hook up a click in the summary that scrolls the associated input field/element into view and sets focus.
    • errorCode - Identifies the validator supplying the issue.
    • severity - Helps style the error. Expect Severe, Error, and Warning levels.
    • errorMessage - Fully prepared, tokens replaced and formatting rules applied
    • summaryMessage - The message suited for a Validation Summary widget.
  • A list of all issues from all InputValueHosts optionally for a given group. Use with a Validation Summary widget and when validating the Model itself.

    Parameters

    • Optional group: string

      Omit or null to ignore groups. Otherwise this will match to InputValueHosts with the same group (case insensitive match).

    Returns null | IssueFound[]

    An array of issues found. When null, there are no issues and the data is valid. If there are issues, when all have severity = warning, the data is also valid. Anything else means invalid data. Each contains:

    • name - The name for the ValueHost that contains this error. Use to hook up a click in the summary that scrolls the associated input field/element into view and sets focus.
    • errorCode - Identifies the validator supplying the issue.
    • severity - Helps style the error. Expect Severe, Error, and Warning levels.
    • errorMessage - Fully prepared, tokens replaced and formatting rules applied.
    • summaryMessage - The message suited for a Validation Summary widget.
  • Use to change anything in ValueHostsManagerInstanceState without impacting the immutability of the current instance. Your callback will be passed a cloned instance. Change any desired properties and return that instance. It will become the new immutable value of the instanceState property.

    Parameters

    • updater: ((stateToUpdate) => TState)

      Your function to change and return a state instance.

    Returns boolean

    true when the state did change. false when it did not.

  • Adds a ValueHostConfig for a ValueHost not previously added. Does not trigger any notifications. Exception when the same ValueHostConfig.name already exists.

    Parameters

    • config: ValueHostConfig

      a clone of this instance will be retained. Can use builder.static(), builder.calc() or any ValueConfigHost. (builder is the Builder API)

    • initialState: null | ValueHostInstanceState

      When not null, this state object is used instead of an initial state. It overrides any state supplied by the ValueHostsManager constructor. It will be run through ValueHostFactory.cleanupInstanceState() first. When null, the state supplied in the ValueHostsManager constructor will be used if available. When neither state was supplied, a default state is created.

    Returns IValueHost

  • Replaces a ValueHostConfig for an already added ValueHost. It does not merge. If merging is required, use the ValueHostConfigMergeService first. Does not trigger any notifications. If the name isn't found, it will be added. Any previous ValueHost and its config will be disposed. Be sure to discard any reference to the ValueHost instance that you have.

    Parameters

    • config: ValueHostConfig

      a clone of this instance will be retained. Can use builder.static(), builder.calc() or any ValueConfigHost. (builder is the Builder API)

    • initialState: null | ValueHostInstanceState

      When not null, this state object is used instead of an initial state. It overrides any state supplied by the ValueHostsManager constructor. It will be run through ValueHostFactory.cleanupInstanceState() first.

    Returns IValueHost

  • Replaces a ValueHostConfig for an already added ValueHost. It merges the new config with the existing one using the ValueHostConfigMergeService. The goal is to protect important business logic settings while allowing the UI to inject new property values where appropriate. Does not trigger any notifications. If the name isn't found, it will be added. Any previous ValueHost and its config will be disposed. Be sure to discard any reference to the ValueHost instance that you have.

    Parameters

    • config: ValueHostConfig

      a clone of this instance will be retained. Can use builder.static(), builder.calc() or any ValueConfigHost. (builder is the Builder API)

    • initialState: null | ValueHostInstanceState

      When not null, this state object is used instead of an initial state. It overrides any state supplied by the ValueHostsManager constructor. It will be run through ValueHostFactory.cleanupInstanceState() first.

    Returns IValueHost

  • Creates the IValueHost based on the config and ensures ValueHostsManager has correct and corresponding instances of ValueHost, ValueHostConfig and ValueHostInstanceState. Any previous ValueHost and its config will be disposed.

    Parameters

    • config: ValueHostConfig

      a clone of this instance will be retained

    • initialState: null | ValueHostInstanceState

      When not null, this ValueHost state object is used instead of an initial state. It overrides any state supplied by the ValueHostsManager constructor. It will be run through ValueHostFactory.cleanupInstanceState() first.

    Returns IValueHost

Generated using TypeDoc v0.25.12