40 lines
818 B
JavaScript
40 lines
818 B
JavaScript
/**
|
|
@license
|
|
Copyright (c) 2025 trading_peter
|
|
This program is available under Apache License Version 2.0
|
|
*/
|
|
|
|
import { FormElement } from '@tp/helpers/form-element.js';
|
|
import { LitElement, css } from 'lit';
|
|
|
|
class TpElement extends FormElement(LitElement) {
|
|
static get styles() {
|
|
return [
|
|
css`
|
|
:host {
|
|
display: none;
|
|
}
|
|
`
|
|
];
|
|
}
|
|
|
|
static get properties() {
|
|
return {
|
|
errorMessage: { type: String },
|
|
};
|
|
}
|
|
|
|
validate() {
|
|
if (!this.required) return true;
|
|
|
|
const isValid = this.value !== undefined && this.value !== null;
|
|
if (!isValid) {
|
|
this.dispatchEvent(new CustomEvent('invalid', { detail: this.errorMessage, bubbles: true, composed: true }));
|
|
}
|
|
|
|
return isValid;
|
|
}
|
|
}
|
|
|
|
window.customElements.define('tp-form-value', TpElement);
|