Allows to set validation errors for the form fields. If validation errors are set, the submit button will be disabled.
Array of objects with fieldKey and error properties.
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);
}
}
);
Event fired whenever any of the notification form fields changes.
"notification-form-value-changed"