Implement this interface when your condition should evaluate the text of your Input as its being edited. Your evaluateDuringEdit() function is called by the Validator.validate() function instead of the ICondition.evaluate() when validateOption.DuringEdit is true. This is a specialized validator, and not part of model validation. Instead, it takes a string that is provided by the UI Input (via InputValueHost.setInputValue()) and determines if the content is valid. Most validation is based on the already converted native value, like comparing two values. This validation should be limitd to rules that are limited to a string that is likely not in good enough shape to be converted to native. Examples:

  • RequireText: does the string have any non-whitespace text?
  • Reg exp to check for invalid characters, such as entering a password. This allows you to report immediate problems as the user types.
  • String length: if the user has exceeded the maximum, they know immediately. In fact, the provided RequireTextCondition, RegExpCondition, and StringLengthCondition have already been setup for this, although their ConditionConfigs let you disable this feature.

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.errorCode property unless overridden in ValidatorConfig.errorCode. It allows the consumer of both to correlate those instances with the specific condition. When defining conditions through a ConditionConfig, the conditionType property must be assigned with a valid 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.

    • valueHostResolver: IValueHostResolver

      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

Generated using TypeDoc v0.25.12