For any input field/element whose native data is a string to determine if the required rule has been met or not, optionally require the absence of surrounding whitespace and optionally not null in native value. It has two evaluation features:

  • ICondition.evaluate() evaluates the native value. It ignores the trim property.
  • IEvaluateConditionDuringEdits.evaluateDuringEdit() evaluates the input value as the user is editing the input. It is invoked by InputValueHost.setInputValue(option.DuringEdit = true) and supports the trim property.

Hierarchy (view full)

Implements

Constructors

Accessors

  • get conditionType(): string
  • A unique identifier for the specific implementation, like "RequireText" or "Range". Its value appears in the IssueFound that comes from Validation, and in IssueFound that comes from retrieving a list of errors to display. It allows the consumer of both to correlate those instances with the specific condition. When defining conditions through a ConditionConfig, the Type property must be assigned with a valid ConditionType. This property always returns what the user supplied in the Config.conditionType, not the default conditiontype. That allows multiple instances of the same condition Class to participate in one validator's list of conditions, because each has a unique ConditionType.

    Returns string

  • get category(): ConditionCategory
  • Helps identify the purpose of the Condition. Impacts:

    • Sort order of the list of Conditions evaluated by an Validator, placing Require first and DataTypeCheck second.
    • Sets InputValueHostConfig.requiresInput.
    • Sets ValidatorConfig.severity when undefined, where Require and DataTypeCheck will use Severe. Others will use Error. Many Conditions have this value predefined. However, all will let the user override it with ConditionConfig.category.

    Returns ConditionCategory

Methods

  • Evaluate something against the rules defined in the implementation. Return whether the data was consistent or violates the rules, or the data couldn't be used to run the rule.

    Parameters

    • valueHost: null | IValueHost

      Most values are found amongst the ValueHosts in the ValueHostsManager. Conditions can look them up using ValueHostsManager.getValueHost().getValue() or getInputValue(). This parameter is used as an optimization, both to avoid that lookup and to avoid the user typing in a ValueHostName when creating the Condition instance. Validator.validate() knows to pass the ValueHostName that hosts the Validator. Expect this to be null in other cases, such as when Condition is a child of the AllMatchCondition and its peers. In otherwords, support both ways.

    • valueHostsManager: IValueHostsManager

      Its primary use is to lookup ValueHosts to get their data.

    Returns ConditionEvaluateResult | Promise<ConditionEvaluateResult>

    Any of these values:

    • Match - consistent with the rule
    • NoMatch - violates the rule
    • Undetermined - Cannot invoke the rule. Usually data incompatible with use within the rule, like the value is null, undefined, or the wrong data type.
  • Evaluates the text from an Input that is actively being edited to determine if it violates the rules of this condition. However, this implementation is often very different from the implementation built around the native value. It works with a string value from the Input, and you aren't expected to retrieve any other value from a ValueHost host.

    Parameters

    • text: string

      Current Input Value from InputValueHost. It has not been modified, so if you need to work with trimmed (lead and trail whitespace removed) text, you must take care of that yourself.

    • valueHost: IInputValueHost

      the ValueHost that invoked this.

    • services: IValidationServices

      just in case, your logic needs more info. However, if the data you need is constant, add a property to your condition's ConditionConfig to supply it.

    Returns ConditionEvaluateResult

  • Implementation for IMessageTokenSource. Conditions havea number of values that are appropriate for tokens on the ConditionConfig. Examples:

    • In RangeCondition, Minimum and Maximum properties become {Mininum} and {Maximum} tokens.
    • In CompareToValueCondition, secondValueHostName property is the source for the {CompareTo} token. This implementation feels like it violates Single Responsibility pattern. But keeping this feature separate from conditions greatly increases complexity.

    Parameters

    Returns TokenLabelAndValue[]

    An array. If an empty array if there are no token to offer. This base class has no tokens to offer.

  • Converts the given value and lookup key using the provided conversion lookup key. If the conversion fails, a warning log is generated. Takes no action if the conversionLookupKey is null.

    Parameters

    • value: any

      The value to be converted.

    • valueLookupKey: undefined | null | string

      The lookup key associated with the value. Often this should be assigned to valueHost.getDataType().

    • conversionLookupKey: undefined | null | string

      The conversion lookup key to be used for conversion. Often this comes from conversionLookupKey or secondConversionLookupKey found on the Config object.

    • services: IValueHostsServices

      The services

    Returns {
        value?: any;
        lookupKey?: null | string;
        failed: boolean;
    }

    An object containing the converted value, lookup key, and a flag indicating if the conversion failed.

    • Optional value?: any
    • Optional lookupKey?: null | string
    • failed: boolean

Generated using TypeDoc v0.25.12