MonitorAttributeErrors

Watches the DOM for `data-monster-error` attributes and can forward them to `monster-notify`.

Import
the javascript logo
import { MonitorAttributeErrors } from "@schukai/monster/source/components/notify/monitor-attribute-errors.mjs";
Source
the git logo
Package
the npm logo
Since
3.98.0
Validation target without errors
Trigger attribute errorClear attribute error

Introduction

monster-monitor-attribute-errors watches the DOM for data-monster-error attributes and can surface those issues to users or developers.

Key Features

  • Mutation-based monitoring: Observes dynamic DOM changes.
  • Console diagnostics: Logs grouped error details for debugging.
  • Optional user notification: Can forward detected errors to monster-notify.

Monitor Attribute Errors Simple

This example monitors the document for data-monster-error attributes and forwards them to monster-notify.

Watched element
Trigger attribute errorClear attribute error

Javascript

import "@schukai/monster/source/components/notify/notify.mjs";
import "@schukai/monster/source/components/notify/monitor-attribute-errors.mjs";
import "@schukai/monster/source/components/form/button.mjs";

const target = document.getElementById("monitor-error-target");
const trigger = document.getElementById("monitor-error-trigger");
const clear = document.getElementById("monitor-error-clear");

trigger.addEventListener("click", () => {
  target.textContent = "Watched element with active validation issues";
  target.setAttribute(
    "data-monster-error",
    "Example validation error::Another monitored issue",
  );
});

clear.addEventListener("click", () => {
  target.textContent = "Watched element";
  target.removeAttribute("data-monster-error");
});<script type="module">import "@schukai/monster/source/components/notify/notify.mjs";
import "@schukai/monster/source/components/notify/monitor-attribute-errors.mjs";
import "@schukai/monster/source/components/form/button.mjs";

const target = document.getElementById("monitor-error-target-run");
const trigger = document.getElementById("monitor-error-trigger-run");
const clear = document.getElementById("monitor-error-clear-run");

trigger.addEventListener("click", () => {
  target.textContent = "Watched element with active validation issues";
  target.setAttribute(
    "data-monster-error",
    "Example validation error::Another monitored issue",
  );
});

clear.addEventListener("click", () => {
  target.textContent = "Watched element";
  target.removeAttribute("data-monster-error");
});</script>

HTML

<monster-notify id="monitor-error-notify"></monster-notify>
<monster-monitor-attribute-errors
  id="monitor-error-demo"
  data-monster-option-features-notify-user="true"
  data-monster-option-notify-user-selector="#monitor-error-notify"
></monster-monitor-attribute-errors>

<div
  id="monitor-error-target"
  style="padding:0.75rem;border:1px solid var(--monster-color-primary-2);border-radius:var(--monster-border-radius);"
>
  Watched element
</div>

<div style="display:flex;flex-wrap:wrap;gap:var(--monster-space-3);margin-top:var(--monster-space-4);">
  <monster-button id="monitor-error-trigger">Trigger attribute error</monster-button>
  <monster-button id="monitor-error-clear">Clear attribute error</monster-button>
</div>

Stylesheet

/** no additional stylesheet is defined **/
Open in playground

Component Design

The component uses mutation observers on the document and open shadow roots to detect newly added error attributes.

Configuration

  • features.notifyUser: Enables notification forwarding.
  • notifyUser.selector: Points to the notify component that should receive messages.

HTML Structure

<monster-monitor-attribute-errors></monster-monitor-attribute-errors>

JavaScript Initialization

const element = document.createElement('monster-monitor-attribute-errors');
document.body.appendChild(element);

Exported

MonitorAttributeErrors

Derived from

CustomElement

Options

The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomElement.

Option
Type
Default
Description
templates
object
Template definitions
templates.main
string
undefined
Main template
features
object
Features
features.notifyUser
boolean
false
Notify user (monster-notify control is required)
notifyUser
object
Notify user
notifyUser.selector
string
monster-notify
Selector for the notify user control (feature notifyUser must be enabled)

  • since
  • deprecated

Properties and Attributes

The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomElement.

  • data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.
  • data-monster-option-[name]: Sets the value of the configuration option [name] for the collapse component when used as an HTML attribute.

Methods

The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomElement.

Static methods

[instanceSymbol]()
This method is called by the instanceof operator.
getCSSStyleSheet()
Returns
  • {CSSStyleSheet[]}
getTag()
Returns
  • {string}

Lifecycle methods

Lifecycle methods are called by the environment and are usually not intended to be called directly.

[assembleMethodSymbol]()
Returns
  • {Components.Notify.MonitorAttributeErrors
connectedCallback()
Returns
  • {void}
disconnectedCallback()
Returns
  • {void}

Events

This component does not fire any public events. It may fire events that are inherited from its parent classes.

The current width of the area is too small to display the content correctly.