AboutSupportDeveloper GuideVersion 18.0.9

Interface NotificationFormValuesChangedEvent

Event fired whenever any of the notification form fields changes.

"notification-form-value-changed"

Hierarchy

  • NotificationFormValuesChangedEvent

Properties

form: Record<string, unknown>
notification: Readonly<Object>
setErrors: ((validationErrors) => Promise<void>)

Type declaration

    • (validationErrors): Promise<void>
    • Allows to set validation errors for the form fields. If validation errors are set, the submit button will be disabled.

      Parameters

      Returns Promise<void>

      Promise that resolves when the validation errors are set.

      Example

      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"