@formstack/forms-renderer
    Preparing search index...

    Interface IFieldApi

    interface IFieldApi {
        formId: string;
        getTypeAttribute: TGetTypeAttribute<
            | "required"
            | "type"
            | "requireConfirmation"
            | "shouldForceSkipValidation"
            | "usePageBreak",
        >;
        id: string;
        setTypeAttribute: TSetTypeAttribute<
            | "required"
            | "type"
            | "requireConfirmation"
            | "shouldForceSkipValidation"
            | "usePageBreak",
            any,
        >;
        checkAll(): Promise<void>;
        empty(): Promise<void>;
        getCalculationChain(): TCalculationNode[];
        getCalculationChainToString(): string;
        getGeneralAttribute(key: string): any;
        getParentTableMetadata(): any;
        getValue(): IFieldValueUnion;
        goTo(): void;
        reset(): Promise<void>;
        setGeneralAttribute(key: string, value: any): void;
        setSearchFunction(search: TSearchFunction): void;
        setValue(value: IFieldValueUnion): Promise<void>;
        setVisibility(visible: boolean): void;
        uncheckAll(): Promise<void>;
    }

    Hierarchy (View Summary)

    Index

    Properties

    formId: string
    getTypeAttribute: TGetTypeAttribute<
        | "required"
        | "type"
        | "requireConfirmation"
        | "shouldForceSkipValidation"
        | "usePageBreak",
    >
    id: string
    setTypeAttribute: TSetTypeAttribute<
        | "required"
        | "type"
        | "requireConfirmation"
        | "shouldForceSkipValidation"
        | "usePageBreak",
        any,
    >

    Methods

    • Returns Promise<void>

    • Sets the field to a safe empty value (according to its type).

      Returns Promise<void>

    • Returns string

    • Returns the value of the field. This will always be an object as some fields can have multiple values (e.g., Address field can have Address1, Address2, City, Province, Country values)

      Returns IFieldValueUnion

    • Resets the field to its default value. The default value is either one set for this specific field (e.g. via setGeneralAttribute('defaultValue')) or the default value of all fields of this type (e.g. an empty string for Short Answer fields).

      Returns Promise<void>

    • Sets an override search function for searchable fields (Dropdowns, etc.)

      Parameters

      Returns void

      Implementing a custom local search

      field.setSearchFunction((query, fieldId, options) => {
      return new Promise((resolve) => {
      // if the field is field 1, it should not show invalid options for this specific field
      resolve(options.filter(o => (query && o.label.indexOf(query) !== -1) && (fieldId !== '1' || o.value !== 'invalid')));
      });
      });

      Implementing a custom remote search

      field.setSearchFunction((query, fieldId, options) => {
      return fetch(`https://my-endpoint/options?query=${query}&id=${fieldId}`)
      .then(resonse => {
      // for an endpoint with a JSON payload
      return resonse.json();
      }).then(data => {
      // endpoint doesn't return field options, but some other custom model
      return data.items.map(i => ({ label: i.text, value: i.key, id: i.key }));
      });
      });
    • Returns Promise<void>