Interface SmiFieldControlApi<ControlTypeAttributes, Type>

The API for the methods and properties on a field control.

interface SmiFieldControlApi<ControlTypeAttributes, Type> {
    control: {
        form: SmiSingleValueControlFormApi;
        masking: MaskingControlApi;
        state: ControlStateApi;
        uuid: string;
        applyDefaultFieldValue(value: undefined | FieldTypeToValue<Type>): void;
        getControl(): Control<ControlTypeAttributes>;
        getFieldRestrictions(): FieldTypeToRestrictions<Type>;
        getFieldValue(): undefined | string | FieldTypeToValue<Type>;
        isMasked(): boolean;
        mask(): void;
        maskedCancel(): void;
        maskedEdit(): {
            unmask: Promise<undefined | FieldTypeToValue<Type>>;
        };
        onFieldChange(callback: ((change: FieldChange<FieldTypeToValue<Type>>) => void)): void;
        onMask(callback: ((mask: {
            fieldValue: string;
        }) => void)): (() => void);
        onUnmask(callback: ((unmask: {
            fieldValue?: FieldTypeToValue<Type>;
        }) => void)): (() => void);
        reset(): void;
        setFieldValue(value: undefined | FieldTypeToValue<Type>): void;
        unmask(): Promise<undefined | FieldTypeToValue<Type>>;
    };
    page: Omit<ControlPageApiBase, "onChange" | "isHomepage" | "getMode"> & {
        events: PageEventsApi;
        field: {
            isMasked(field: string): boolean;
            mask(field: string): void;
            onAnyMask(callback: ((mask: {
                field: string;
                fieldValue: string;
            }) => void)): (() => void);
            onAnyUnmask(callback: ((unmask: {
                field: string;
                fieldValue?: FieldValue;
            }) => void)): (() => void);
            onFieldChange(callback: ((change: FieldChange<NonNullable<FieldValue>>) => void)): (() => void);
            onMask(field: string, callback: ((mask: {
                fieldValue: string;
            }) => void)): (() => void);
            onReset(field: string, callback: (() => void)): (() => void);
            onUnmask<Type>(field: string, callback: ((unmask: {
                fieldValue?: FieldTypeToValue<Type>;
            }) => void)): (() => void);
            reset(field: string): void;
            unmask<Type>(field: string): Promise<undefined | FieldTypeToValue<Type>>;
        };
        file: {
            addFiles(files: (Blob | File)[], category: string): FileChange;
            deleteByUuids(fileUuids: string[]): FileChange;
            deleteFiles(indexes: number[], category: string): FileChange;
            getAddingCount(category: string): number;
            getByUuid(fileUuid: string): undefined | SmiPageFile;
            getDeletingCount(category: string): number;
            getFiles(category: string): SmiPageFile[];
            getFilesFetch(): undefined | Promise<{
                [category: string]: SmiPageFile[];
            }>;
            onFileChange(callback: ((change: FileChange) => void)): void;
            onReset(category: string, callback: (() => void)): (() => void);
            onUploadStart(callback: ((change: UploadFileChange) => void)): (() => void);
            reset(category: string): void;
            upload(fileModels: SmiPageFile[]): UploadFileChange;
        };
        isDraft: boolean;
        masking: MaskingPageApi;
        objectLabel?: string;
        uuid: string;
        addMenuItem(options: {
            isDisabled?: (() => boolean);
            onClick: (() => void);
            text: string;
        }): (() => void);
        getActions<T>(name: string): undefined | Action<T>[];
        getMode(): SmiPageMode;
        getReferenceDataLabel(field: string, code: string): undefined | string;
        getUserGroupName(id: string, type: "user" | "group"): undefined | string;
        onModeChange(callback: ((mode: SmiPageMode) => void)): (() => void);
    };
}

Type Parameters

Hierarchy

  • SmiObjectControlApi
    • SmiFieldControlApi

Properties

Properties

control: {
    form: SmiSingleValueControlFormApi;
    masking: MaskingControlApi;
    state: ControlStateApi;
    uuid: string;
    applyDefaultFieldValue(value: undefined | FieldTypeToValue<Type>): void;
    getControl(): Control<ControlTypeAttributes>;
    getFieldRestrictions(): FieldTypeToRestrictions<Type>;
    getFieldValue(): undefined | string | FieldTypeToValue<Type>;
    isMasked(): boolean;
    mask(): void;
    maskedCancel(): void;
    maskedEdit(): {
        unmask: Promise<undefined | FieldTypeToValue<Type>>;
    };
    onFieldChange(callback: ((change: FieldChange<FieldTypeToValue<Type>>) => void)): void;
    onMask(callback: ((mask: {
        fieldValue: string;
    }) => void)): (() => void);
    onUnmask(callback: ((unmask: {
        fieldValue?: FieldTypeToValue<Type>;
    }) => void)): (() => void);
    reset(): void;
    setFieldValue(value: undefined | FieldTypeToValue<Type>): void;
    unmask(): Promise<undefined | FieldTypeToValue<Type>>;
}

Type declaration

  • Readonlyform: SmiSingleValueControlFormApi
  • masking: MaskingControlApi
  • Readonlystate: ControlStateApi
  • Readonlyuuid: string
  • applyDefaultFieldValue:function
    • Applies a default value to the control's implicit field. Note that this will only apply the default value if it is applicable.

      Parameters

      Returns void

  • getControl:function
  • getFieldRestrictions:function
  • getFieldValue:function
  • isMasked:function
    • Determines whether the control's implicit field is masked.

      Returns boolean

      A boolean.

      In favour of the methods at this.controlApi.control.masking.

  • mask:function
    • Masks the control's implicit field.

      Returns void

      In favour of the methods at this.controlApi.control.masking.

  • maskedCancel:function
    • Cancels a masked edit of the control, setting the control's field value back to what it was when the edit started.

      Returns void

      In favour of the methods at this.controlApi.control.masking.

  • maskedEdit:function
    • Unmasks the control's field value so that the user can edit it. If unauthorized, it shows a confirmation dialog box and, on confirm, clears the field value for editing.

      Returns {
          unmask: Promise<undefined | FieldTypeToValue<Type>>;
      }

      An object that contains the unmask promise.

  • onFieldChange:function
    • The supplied callback function will run whenever there is a change in the control's field.

      Parameters

      Returns void

  • onMask:function
    • Invokes the callback whenever the control's implicit field value is masked.

      Parameters

      • callback: ((mask: {
            fieldValue: string;
        }) => void)

        The callback function.

          • (mask): void
          • Parameters

            • mask: {
                  fieldValue: string;
              }
              • fieldValue: string

            Returns void

      Returns (() => void)

      A function that removes the callback.

        • (): void
        • Returns void

      In favour of the methods at this.controlApi.control.masking.

  • onUnmask:function
    • Invokes the callback whenever the control's implicit field value is unmasked. fieldValue is optional for the case where a mode change results in the masked field not being present in the page response.

      Parameters

      Returns (() => void)

      A function that removes the callback.

        • (): void
        • Returns void

      In favour of the methods at this.controlApi.control.masking.

  • reset:function
    • Resets the control's field value to what it was before any edits in the current page mode.

      Returns void

  • setFieldValue:function
    • Sets the value of the control's implicit field.

      Parameters

      Returns void

  • unmask:function
    • Fetches the unmasked field value of the control's implicit field and returns it. Note that this also mutates the entry in the field values map, such that subsequent get field value calls return the unmasked value. If the field is already unmasked the returned promise immediately resolves to the value without the fetch. If the user is not authorized to reveal the redacted field, the returned promise will reject.

      Returns Promise<undefined | FieldTypeToValue<Type>>

      A promise that resolves to the field value.

      In favour of the methods at this.controlApi.control.masking.

page: Omit<ControlPageApiBase, "onChange" | "isHomepage" | "getMode"> & {
    events: PageEventsApi;
    field: {
        isMasked(field: string): boolean;
        mask(field: string): void;
        onAnyMask(callback: ((mask: {
            field: string;
            fieldValue: string;
        }) => void)): (() => void);
        onAnyUnmask(callback: ((unmask: {
            field: string;
            fieldValue?: FieldValue;
        }) => void)): (() => void);
        onFieldChange(callback: ((change: FieldChange<NonNullable<FieldValue>>) => void)): (() => void);
        onMask(field: string, callback: ((mask: {
            fieldValue: string;
        }) => void)): (() => void);
        onReset(field: string, callback: (() => void)): (() => void);
        onUnmask<Type>(field: string, callback: ((unmask: {
            fieldValue?: FieldTypeToValue<Type>;
        }) => void)): (() => void);
        reset(field: string): void;
        unmask<Type>(field: string): Promise<undefined | FieldTypeToValue<Type>>;
    };
    file: {
        addFiles(files: (Blob | File)[], category: string): FileChange;
        deleteByUuids(fileUuids: string[]): FileChange;
        deleteFiles(indexes: number[], category: string): FileChange;
        getAddingCount(category: string): number;
        getByUuid(fileUuid: string): undefined | SmiPageFile;
        getDeletingCount(category: string): number;
        getFiles(category: string): SmiPageFile[];
        getFilesFetch(): undefined | Promise<{
            [category: string]: SmiPageFile[];
        }>;
        onFileChange(callback: ((change: FileChange) => void)): void;
        onReset(category: string, callback: (() => void)): (() => void);
        onUploadStart(callback: ((change: UploadFileChange) => void)): (() => void);
        reset(category: string): void;
        upload(fileModels: SmiPageFile[]): UploadFileChange;
    };
    isDraft: boolean;
    masking: MaskingPageApi;
    objectLabel?: string;
    uuid: string;
    addMenuItem(options: {
        isDisabled?: (() => boolean);
        onClick: (() => void);
        text: string;
    }): (() => void);
    getActions<T>(name: string): undefined | Action<T>[];
    getMode(): SmiPageMode;
    getReferenceDataLabel(field: string, code: string): undefined | string;
    getUserGroupName(id: string, type: "user" | "group"): undefined | string;
    onModeChange(callback: ((mode: SmiPageMode) => void)): (() => void);
}

Type declaration

  • events: PageEventsApi
  • Readonlyfield: {
        isMasked(field: string): boolean;
        mask(field: string): void;
        onAnyMask(callback: ((mask: {
            field: string;
            fieldValue: string;
        }) => void)): (() => void);
        onAnyUnmask(callback: ((unmask: {
            field: string;
            fieldValue?: FieldValue;
        }) => void)): (() => void);
        onFieldChange(callback: ((change: FieldChange<NonNullable<FieldValue>>) => void)): (() => void);
        onMask(field: string, callback: ((mask: {
            fieldValue: string;
        }) => void)): (() => void);
        onReset(field: string, callback: (() => void)): (() => void);
        onUnmask<Type>(field: string, callback: ((unmask: {
            fieldValue?: FieldTypeToValue<Type>;
        }) => void)): (() => void);
        reset(field: string): void;
        unmask<Type>(field: string): Promise<undefined | FieldTypeToValue<Type>>;
    }
    • isMasked:function
      • Determines whether a field is masked.

        Parameters

        • field: string

          The field.

        Returns boolean

        A boolean.

        In favour of the methods at this.controlApi.page.masking.

    • mask:function
      • Masks a field.

        Parameters

        • field: string

          The field.

        Returns void

        In favour of the methods at this.controlApi.page.masking.

    • onAnyMask:function
      • Invokes the callback whenever any field value is masked.

        Parameters

        • callback: ((mask: {
              field: string;
              fieldValue: string;
          }) => void)

          The callback function.

            • (mask): void
            • Parameters

              • mask: {
                    field: string;
                    fieldValue: string;
                }
                • field: string
                • fieldValue: string

              Returns void

        Returns (() => void)

        A function that removes the callback.

          • (): void
          • Returns void

        In favour of the methods at this.controlApi.page.masking

    • onAnyUnmask:function
      • Invokes the callback whenever any field value is unmasked. fieldValue is optional for the case where a mode change results in the masked field not being present in the page response.

        Parameters

        • callback: ((unmask: {
              field: string;
              fieldValue?: FieldValue;
          }) => void)

          The callback function.

            • (unmask): void
            • Parameters

              • unmask: {
                    field: string;
                    fieldValue?: FieldValue;
                }

              Returns void

        Returns (() => void)

        A function that removes the callback.

          • (): void
          • Returns void

        In favour of the methods at this.controlApi.page.masking.

    • onFieldChange:function
      • The supplied callback function will run whenever there is a field change.

        Parameters

        Returns (() => void)

        A function that removes the callback.

          • (): void
          • Returns void

    • onMask:function
      • Invokes the callback whenever the specified field's value is masked.

        Parameters

        • field: string

          The field.

        • callback: ((mask: {
              fieldValue: string;
          }) => void)

          The callback function.

            • (mask): void
            • Parameters

              • mask: {
                    fieldValue: string;
                }
                • fieldValue: string

              Returns void

        Returns (() => void)

        A function that removes the callback.

          • (): void
          • Returns void

        In favour of the methods at this.controlApi.page.masking.

    • onReset:function
      • Add callbacks to know when the field is reset.

        Parameters

        • field: string
        • callback: (() => void)

          Called when the field is reset.

            • (): void
            • Returns void

        Returns (() => void)

        A function that removes the callback.

          • (): void
          • Returns void

    • onUnmask:function
      • Invokes the callback whenever the specified field's value is unmasked. fieldValue is optional for the case where a mode change results in the masked field not being present in the page response.

        Type Parameters

        Parameters

        Returns (() => void)

        A function that removes the callback.

          • (): void
          • Returns void

        In favour of the methods at this.controlApi.page.masking.

    • reset:function
      • Resets the field's value to what it was before any edits in the current page mode.

        Parameters

        • field: string

          The field to reset.

        Returns void

    • unmask:function
      • Fetches the unmasked field value and returns it. Note that this also mutates the entry in the field values map, such that subsequent get field value calls return the unmasked value. If the field is already unmasked the returned promise immediately resolves to the value without the fetch. If the user is not authorized to reveal the redacted field, the returned promise will reject.

        Type Parameters

        Parameters

        • field: string

          The field.

        Returns Promise<undefined | FieldTypeToValue<Type>>

        A promise that resolves to the field value.

        In favour of the methods at this.controlApi.page.masking.

  • Readonlyfile: {
        addFiles(files: (Blob | File)[], category: string): FileChange;
        deleteByUuids(fileUuids: string[]): FileChange;
        deleteFiles(indexes: number[], category: string): FileChange;
        getAddingCount(category: string): number;
        getByUuid(fileUuid: string): undefined | SmiPageFile;
        getDeletingCount(category: string): number;
        getFiles(category: string): SmiPageFile[];
        getFilesFetch(): undefined | Promise<{
            [category: string]: SmiPageFile[];
        }>;
        onFileChange(callback: ((change: FileChange) => void)): void;
        onReset(category: string, callback: (() => void)): (() => void);
        onUploadStart(callback: ((change: UploadFileChange) => void)): (() => void);
        reset(category: string): void;
        upload(fileModels: SmiPageFile[]): UploadFileChange;
    }
    • addFiles:function
      • Adds the given files to the supplied category.

        Parameters

        • files: (Blob | File)[]

          The File or Blob object.

        • category: string

          The file category.

        Returns FileChange

    • deleteByUuids:function
      • Deletes files with a matching UUIDs to those in the supplied array of UUID's.

        Parameters

        • fileUuids: string[]

          Array of file UUIDs to be deleted.

        Returns FileChange

    • deleteFiles:function
      • Deletes the files at the given indexes from the supplied category.

        Parameters

        • indexes: number[]

          The indexes.

        • category: string

          The file category.

        Returns FileChange

    • getAddingCount:function
      • Returns the number of pending adds for the supplied category.

        Parameters

        • category: string

          The category to get the number of pending adds for.

        Returns number

    • getByUuid:function
      • Returns the file with the UUID that matches the supplied UUID.

        Parameters

        • fileUuid: string

          The UUID of the file to be retrieved.

        Returns undefined | SmiPageFile

    • getDeletingCount:function
      • Returns the number of pending deletes for the supplied category.

        Parameters

        • category: string

          The category for which to get the number of pending deletes.

        Returns number

    • getFiles:function
      • Returns the files for the supplied category.

        Parameters

        • category: string

          The file category.

        Returns SmiPageFile[]

    • getFilesFetch:function
      • Returns the files fetch promise for the current object. Files are lazily loaded for children.

        Returns undefined | Promise<{
            [category: string]: SmiPageFile[];
        }>

    • onFileChange:function
      • The supplied callback function will run whenever there is a file change.

        Parameters

        • callback: ((change: FileChange) => void)

          The callback that will be invoked when there is a file change.

            • (change): void
            • Parameters

              Returns void

        Returns void

    • onReset:function
      • Add callbacks to know when the category is reset.

        Parameters

        • category: string
        • callback: (() => void)

          Called when the category is reset.

            • (): void
            • Returns void

        Returns (() => void)

        A function that removes the callback.

          • (): void
          • Returns void

    • onUploadStart:function
      • The callback will run whenever there is an upload of a file.

        Parameters

        Returns (() => void)

        A function that stops the callback running.

          • (): void
          • Returns void

    • reset:function
      • Resets the files of the given category to what they were before any edits were made in the current page mode.

        Parameters

        • category: string

          The category to reset.

        Returns void

    • upload:function
  • ReadonlyisDraft: boolean

    Returns whether the page is a draft.

  • masking: MaskingPageApi
  • OptionalobjectLabel?: string
  • uuid: string
  • addMenuItem:function
    • Adds a menu item for the page. Note that this applies to object pages that are not part of a wizard, that is, adding a menu item to the parent object header.

      Parameters

      • options: {
            isDisabled?: (() => boolean);
            onClick: (() => void);
            text: string;
        }

        The options for the menu item: the text string, a click listener function, and an optional function to disable the item.

        • OptionalisDisabled?: (() => boolean)
            • (): boolean
            • Returns boolean

        • onClick: (() => void)
            • (): void
            • Returns void

        • text: string

      Returns (() => void)

      A function that removes the menu item.

        • (): void
        • Returns void

  • getActions:function
    • Returns the actions for the given name.

      Type Parameters

      Parameters

      • name: string

        The action name.

      Returns undefined | Action<T>[]

      An array of all the actions.

  • getMode:function
  • getReferenceDataLabel:function
    • Returns the reference data label for a given reference data field and code. Note that this is relevant only in View mode, when labels for codes in the field values are returned in the data source part of the page response (meaning there is no need to fetch all reference data).

      Parameters

      • field: string

        The reference data field.

      • code: string

        The reference data code.

      Returns undefined | string

  • getUserGroupName:function
    • Returns the user group name for the given ID and type. Note that only names that are given as part of the pages' users or groups can be returned (i.e. existing user group values from field values).

      Parameters

      • id: string

        The ID of the user group.

      • type: "user" | "group"

        The type of the user group.

      Returns undefined | string

  • onModeChange:function
    • Invokes the callback whenever a page changes mode.

      Parameters

      • callback: ((mode: SmiPageMode) => void)

        The callback function.

      Returns (() => void)

      A function that removes the callback.

        • (): void
        • Returns void