Wagtail client-side components
    Preparing search index...

    Adds the ability for a controlled form element to conditionally enable targeted elements based on the data from the controlled form along with a set of rules to match against that data.

    <form data-controller="w-rules" data-action="change->w-rules#resolve">
    <select name="fav-drink" required>
    <option value="">Select a drink</option>
    <option value="coffee">Coffee</option>
    <option value="other">Other</option>
    </select>
    <button type="button" data-w-rules-target="enable" data-w-rules='{"fav-drink": ["coffee"]}'>
    Continue
    </button>
    </form>

    Hierarchy

    Index

    Constructors

    • Parameters

      • context: Context

      Returns RulesController

    Properties

    context: Context
    enableTargets: FormControlElement[]

    Targets will be enabled if the target's rule matches the scoped form data, otherwise will be disabled.

    form: any
    hasEnableTarget: boolean

    True if there is at least one enable target, used to ensure rules do not run if not needed.

    rulesCache: Record<string, [string, string[]][]>
    blessings: (<T>(constructor: Constructor<T>) => any)[]
    outlets: string[]
    targets: string[] = ...
    values: ValueDefinitionMap

    Accessors

    • get application(): Application

      Returns Application

    • get classes(): ClassMap

      Returns ClassMap

    • get data(): DataMap

      Returns DataMap

    • get element(): ElementType

      Returns ElementType

    • get identifier(): string

      Returns string

    • get outlets(): OutletSet

      Returns OutletSet

    • get scope(): Scope

      Returns Scope

    • get targets(): TargetSet

      Returns TargetSet

    • get shouldLoad(): boolean

      Returns boolean

    Methods

    • Returns void

    • Returns void

    • Parameters

      • eventName: string
      • Optional__namedParameters: Partial<
            {
                bubbles: boolean;
                cancelable: boolean;
                detail: Object;
                prefix: string;
                target: Element
                | Window
                | Document;
            },
        >

      Returns CustomEvent<Object>

    • Finds & parses the rules for the provided target by the rules attribute, which is determined via the identifier (e.g. data-w-rules). Check the rules cache first, then parse the rules for caching if not found.

      When parsing the rule, assume an Object.entries format or convert an object to this format. Then ensure each value is an array of strings for consistent comparison to FormData values.

      Parameters

      Returns [string, string[]][]

    • Resolve the conditional targets based on the form data and the target(s) rule attributes and the controlled element's form data.

      Returns void

    • Parameters

      • _identifier: string
      • _application: Application

      Returns void