-
Notifications
You must be signed in to change notification settings - Fork 841
feat(ui): dispatch validation events from TextField #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,18 @@ export class TextField extends Root { | |
| return; | ||
| } | ||
|
|
||
| this.dispatchEvent( | ||
| new CustomEvent("a2ui-validation-input", { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be an There's an example of an extension of CustomEvent here. In this case, I think the event should be in |
||
| bubbles: true, | ||
| composed: true, | ||
| detail: { | ||
| componentId: this.id, | ||
| value: evt.target.value, | ||
| valid: evt.target.checkValidity(), | ||
| }, | ||
| }) | ||
| ); | ||
dmandar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| this.#setBoundValue(evt.target.value); | ||
| }} | ||
| name="data" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (This is where having a custom event type would help to access |
||
|
|
||
| // 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 | ||
| ); | ||
dmandar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| render() { | ||
| return html` | ||
| <header> | ||
|
|
||
There was a problem hiding this comment.
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.