Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions renderers/lit/src/0.8/ui/text-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ export class TextField extends Root {
return;
}

this.dispatchEvent(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of this block seems wrong.

new CustomEvent("a2ui-validation-input", {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an A2UIValidationEvent extends CustomEvent, with a specific signature for the detail property, so it can be accessed safely later?

There's an example of an extension of CustomEvent here. In this case, I think the event should be in web_core, so it can be shared with other renderers; or is this a Lit-only functionality?

bubbles: true,
composed: true,
detail: {
componentId: this.id,
value: evt.target.value,
valid: evt.target.checkValidity(),
},
})
);

this.#setBoundValue(evt.target.value);
}}
name="data"
Expand Down
24 changes: 24 additions & 0 deletions samples/client/lit/component_gallery/component-gallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,40 @@ export class A2UIComponentGallery extends SignalWatcher(LitElement) {

async connectedCallback() {
super.connectedCallback();
this.addEventListener("a2ui-validation-input", this.#handleValidationInput);
await this.#initiateSession();
}

override disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener("a2ui-validation-input", this.#handleValidationInput);
}

async #initiateSession() {
const message: v0_8.Types.A2UIClientEventMessage = {
request: "START_GALLERY"
};
await this.#sendAndProcessMessage(message);
}

// Debug Validation Events
#handleValidationInput = (e: Event) => {
const detail = (e as CustomEvent).detail;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is where having a custom event type would help to access detail in a type-safe way)


// Log to Console
console.log(
`%c[Validation] Component: ${detail.componentId} | Valid: ${detail.valid} | Value: "${detail.value}"`,
detail.valid ? "color: green" : "color: red; font-weight: bold"
);

// Log to Debug Panel
this.#log(
"info",
`Validation: ${detail.componentId} is ${detail.valid ? "VALID" : "INVALID"}`,
detail
);
};

render() {
return html`
<header>
Expand Down
Loading