OpenFin Workspace API
    Preparing search index...

    Interface NotificationFormValuesChangedEvent

    Event fired whenever any of the notification form fields changes.

    "notification-form-value-changed"

    interface NotificationFormValuesChangedEvent {
        form: Record<string, unknown>;
        notification: Readonly;
        setErrors: (validationErrors: CustomValidationError[]) => Promise<void>;
        type: "notification-form-values-changed";
    }
    Index
    form: Record<string, unknown>
    notification: Readonly
    setErrors: (validationErrors: CustomValidationError[]) => Promise<void>

    Allows to set validation errors for the form fields. If validation errors are set, the submit button will be disabled.

    Type Declaration

      • (validationErrors: CustomValidationError[]): Promise<void>
      • Parameters

        Returns Promise<void>

        Promise that resolves when the validation errors are set.

    addEventListener(
    'notification-form-values-changed',
    async (formValueChanged: NotificationFormValuesChangedEvent) => {
    const errors = [];

    // Simpler regular expression to test for a valid HTTP or HTTPS URL
    const phonePattern = /^\(?([0-9]{3})\)?[- ]?([0-9]{3})[- ]?([0-9]{4})$/;

    // Simpler regular expression to test for a valid email address
    const emailPattern = /^\S+@\S+\.\S+$/;

    // Fields to validate
    const sourcePhone = formValueChanged.form.sourcePhone as string;
    const email = formValueChanged.form.sourceEmail as string;

    // Validate sourceUrl if it's not null or undefined
    if (sourcePhone && !phonePattern.test(sourcePhone)) {
    errors.push({
    fieldKey: 'sourcePhone',
    error: 'Invalid phone format'
    });
    }

    // Validate email if it's not null or undefined
    if (email && !emailPattern.test(email)) {
    errors.push({
    fieldKey: 'sourceEmail',
    error: 'Invalid email format'
    });
    }

    // If there are any errors, set them all at once
    if (errors.length > 0) {
    await formValueChanged.setErrors(errors);
    }
    }
    );
    type: "notification-form-values-changed"