import { html, property } from '@skhemata/skhemata-base'; import { SkhemataFormInput } from './SkhemataFormInput'; export class SkhemataFormCheckbox extends SkhemataFormInput { @property({ type: Boolean }) checked: boolean = false; constructor() { super(); this.value = false; } reset() { this.clearError(); this.checked = false; this.value = false; } validate() { this.helpClass = ''; if (this.required && this.checked === false) { this.valid = false; this.helpClass = 'is-danger'; this.errorMessage = this.getStr('formErrorRequired'); this.requestUpdate(); } this.dispatchEvent( new CustomEvent('is-valid', { detail: { valid: this.valid }, bubbles: true, composed: true, }) ); } handleClick(event: any) { this.clearError(); this.checked = event.target.checked; this.value = event.target.checked; } updated() { const checkbox = this.shadowRoot.querySelector('[type=checkbox]'); checkbox['checked'] = this.value; } render() { const field = html`
${this.description}
` : null }${this.errorMessage}
` : `` }${this.description}
` : null}