Options
All
  • Public
  • Public/Protected
  • All
Menu

This class is used to pass down a shared context accessible from all points of the framework and outside of it. The instance being shared is simply passed down through a SchemaNode's parameter so it's accessible at every level.

Type parameters

Hierarchy

  • DeclarativeFormContext

Implements

  • FormContext

Index

Constructors

Properties

decorators: Decorator[] = []
features: { asyncValidation?: boolean; defaultOptionToFirstValue?: boolean; enableFormatValidator?: boolean; nodePathCollision?: "throw" | "warn" | "ignore" }

Type declaration

  • Optional asyncValidation?: boolean

    False by default When enabled, changing a node's value will not trigger a validation instantly. the user will have to manually call validate on the node to compute errors.

  • Optional defaultOptionToFirstValue?: boolean

    controls if an node of type option with no value should be initially set to the first option

  • Optional enableFormatValidator?: boolean

    False by default Format is disabled until core fixes the js regexes sent. We formely had issues in production with ruby patterns such as \p{Katakana} and \p{Hiragana} which didn't translated into a valid regex.

  • Optional nodePathCollision?: "throw" | "warn" | "ignore"

    Tells the library what to do when a node is being created using a path that was already taken. the path pointer will always point to the last created node unless throw is used.

formatters: ObjectMap<FormatterFn> & { local?: FormatterFn; remote?: FormatterFn }
nodes: Map<string, SchemaNode<any>> = ...
sharedContext: T
translators: ObjectMap<TranslatorFn> & { error?: TranslatorFn; label?: TranslatorFn }
validators: ObjectMap<ValidatorFn<any>> & { Format?: ValidatorFn<ObjectMap<any>>; Length?: ValidatorFn<ObjectMap<any>>; Presence?: ValidatorFn<ObjectMap<any>> }

Here is where we pass validators used for the frontend validation process. by nature a validator returns instantly a validation error or null but since it receives the node as an argument, it's also possible to act asynchronously on the node if the validation process requires an external api or network call.

validators: {
...defaultValidators,
customValidator,
}

A few examples validators that come with the lib are presenceValidator, lengthValidator and formatValidator

values: ObjectMap<any>

Methods

  • addInitialValuesAfterNode(nodeShortPath: string, values: ObjectMap<any>): void
  • focusField(nodePath?: string): void
  • updateContext<K>(valueOrKey: K | Partial<T>, value?: Partial<T[K]>): void
  • Updates the shared context updating passing a single object as the first argument merges the object and retriggers every watcher on sharedContext while using a key/value retriggers only watchers that looks for the changed value.

    Type parameters

    • K: string | number | symbol

    Parameters

    • valueOrKey: K | Partial<T>
    • Optional value: Partial<T[K]>

    Returns void

  • where(fn: DecoratorMatcher): Omit<Decorator, "apply">
  • Decorations are applied once when the node is constructed later. Normally, the where condition should not receive parameters from outside the function scope if the value is dynamic

    Parameters

    • fn: DecoratorMatcher

    Returns Omit<Decorator, "apply">

    chainable Decorator

Generated using TypeDoc