Constructor
Provides ValidationManager with numerous configuration settings. It is just a simple object that you may initialize like this:
{
services: createValidationServices(); <-- see and customize your create_services.ts file
valueHostConfigs: [
// see elsewhere for details on ValueHostConfigs as they are the heavy lifting in this system.
// Just know that you need one object for each value that you want to connect
// to the Validation Manager
],
savedInstanceState: null, // or the state object previously returned with OnInstanceStateChanged
savedValueHostInstanceStates: null, // or an array of the state objects previously returned with OnValueHostInstanceStateChanged
onInstanceStateChanged: (validationManager, state)=> { },
onValueHostInstanceStateChanged: (valueHost, state) => { },
onValidationStateChanged: (validationManager, validationState)=> { },
onValueHostValidationStateChanged: (valueHost, valueHostValidationState) => { },
onValueChanged: (valueHost, oldValue) => { },
onInputValueChanged: (valueHost, oldValue) => { }
onConfigChanged: (valueHost, valueHostConfig) => { }
}
Protected
configProvides access to ValidationServices (override IServices).
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
doNotSave|doNotSave as the ultimate guide to saving. When false, there is at least one validation error.
Determines if a validator doesn't consider the ValueHost's value ready to save based on the latest call to validate(). (It does not run validate().) True when at least one ValueHost's ValidationStatus is Invalid or NeedsValidation
When true, an async Validator is running in any ValueHost
Called when ValidationManager's validate() function has returned. Supplies the result to the callback. Examples: Use to notify the Validation Summary widget(s) to refresh. Use to change the disabled state of the submit button based on validity.
Called when ValueHost's validate() function has returned. Also when validation is cleared or BusinessLogicErrors are added or removed. Supplies the result to the callback. Examples: Use to notify the validation related aspects of the component to refresh, such as showing error messages and changing style sheets. Use to change the disabled state of the submit button based on validity. You can setup the same callback on individual ValueHosts. Here, it aggregates all ValueHost notifications.
Protected
loggerProvides an API for logging, sending entries to the loggerService.
Protected
valueValueHosts for all ValueHostConfigs. Always replace a ValueHost when the associated Config or InstanceState are changed.
Protected
valueValueHostConfigs supplied by the caller (business logic). Always replace a ValueHost when its Config changes.
Protected
instanceValueHostInstanceStates and more. A copy of this is expected to be retained (redux/localstorage/etc) by the caller to support recreating the ValueHostsManager in a stateless situation.
Alternative to getValueHost that returns strongly typed valuehosts in a shortened syntax. Always throws exceptions if the value host requested is unknown or not the expected type.
Use this when caching the configuration for a later creation of ValueHostsManager.
Called when the configuration of ValueHosts has been changed, usually through the ValueHostsManagerConfigModifier.apply, or these members of ValueHostsManager: addValueHost, addOrUpdateValueHost, addOrMergeValueHost, discardValueHost. The supplied object is a clone so modifications will not impact the ValueHostsManager.
Called when the ValueHostsManager's state has changed. React example: React component useState feature retains this value and needs to know when to call its setState function with the stateToRetain
Called when any ValueHost had its ValueHostInstanceState changed. React example: React component useState feature retains this value and needs to know when to call the setValueHostInstanceState() with the stateToRetain. You can setup the same callback on individual ValueHosts. Here, it aggregates all ValueHost notifications.
Called when the ValueHost's Value property has changed. If setup, you can prevent it from being fired with the options parameter of setValue() to avoid round trips where you already know the details. You can setup the same callback on individual ValueHosts. Here, it aggregates all ValueHost notifications.
Called when the InputValueHost's InputValue property has changed. If setup, you can prevent it from being fired with the options parameter of setValue() to avoid round trips where you already know the details. You can setup the same callback on individual InputValueHosts. Here, it aggregates all InputValueHost notifications.
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
Retrieves the ValidatorsValueHostBase of the identified by valueHostName
Matches to the ValidatorsValueHostBaseConfig.name property Returns the instance or null if not found or found a different type of value host.
Retrieves the InputValueHost of the identified by valueHostName
Matches to the IInputValueHost.name property Returns the instance or null if not found or found a non-input valuehost.
Retrieves the PropertyValueHost of the identified by valueHostName
Matches to the IPropertyValueHost.name property Returns the instance or null if not found or found a non-Property valuehost.
Runs validation against all validatable ValueHosts, except those that do not match the validation group supplied in options. Updates this ValueHost's InstanceState and notifies parent if changes were made.
Optional
options: ValidateOptionsProvides guidance on which validators to include.
The ValidationState object, which packages several key pieces of information: isValid, doNotSave, and issues found. The same object is provided through the OnValidated function
Changes the validation state to itself initial: Undetermined with no error messages.
Optional
options: ValidateOptionsProtected
createOptional
options: ValidateOptionsValueHosts 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
Optional
options: ValidateOptionsOptional
force: booleanwhen true, override the debouncer and execute immediately.
Protected
notifyOptional
options: ValidateOptionsWhen 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.
A list of business logic errors to show or null to indicate no errors.
Optional
options: ValidateOptionsOnly considers the skipCallback option.
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.
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:
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.
Optional
group: stringOmit or null to ignore groups. Otherwise this will match to InputValueHosts with the same group (case insensitive match).
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:
Adds or replaces all IssueFound items to the appropriate ValueHosts. Each ValueHost will invoke the onValueHostValidationStateChanged callback if needed.
Use case: client-side getting server-side Jivs-generated IssuesFound, so the UI can incorporate it.
keep or omit an issueFound that does not have a matching validator based on the errorCode. Defaults to Keep
Provides a way to enumerate through existing ValueHosts.
Optional
filter: ((valueHost) => boolean)A generator that yields a tuple of [valueHostName, IValueHost]
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.
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.
a clone of this instance will be retained. Can use builder.static(), builder.calc() or any ValueConfigHost. (builder is the Builder API)
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.
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.
a clone of this instance will be retained. Can use builder.static(), builder.calc() or any ValueConfigHost. (builder is the Builder API)
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.
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.
a clone of this instance will be retained. Can use builder.static(), builder.calc() or any ValueConfigHost. (builder is the Builder API)
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.
Protected
applyCreates 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.
a clone of this instance will be retained
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.
Protected
invokeRetrieves the ValueHost associated with valueHostName
Matches to the IValueHost.name property Returns the instance or null if not found.
Retrieves the StaticValueHost of the identified by valueHostName
Matches to the IStaticValueHost.name property Returns the instance or null if not found or found a non-input valuehost.
Retrieves the CalcValueHost of the identified by valueHostName
Matches to the ICalcValueHost.name property Returns the instance or null if not found or found a non-input valuehost.
Upon changing the value of a ValueHost, other ValueHosts need to know. They may have Conditions that take the changed ValueHost into account and will want to revalidate or set up a state to force revalidation. This goes through those ValueHosts and notifies them.
Report that a ValueHost had its instance state changed. Invokes onValueHostInstanceStateChanged if setup.
Protected
validatableProtected
resolveStatic
safeGenerated using TypeDoc v0.25.12
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:
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.