From b17f9b4aec3b3b1985062951f8610a97b803825d Mon Sep 17 00:00:00 2001 From: pk Date: Tue, 15 Nov 2022 20:21:37 +0100 Subject: [PATCH] Add validation logic --- package.json | 2 +- tp-checkbox.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e1cb4e4..c1692f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-checkbox", - "version": "1.0.4", + "version": "1.0.5", "description": "", "main": "tp-checkbox.js", "scripts": { diff --git a/tp-checkbox.js b/tp-checkbox.js index dc6c805..22b9ca2 100644 --- a/tp-checkbox.js +++ b/tp-checkbox.js @@ -72,6 +72,7 @@ class TpCheckbox extends Inert(ControlState(FormElement(LitElement))) { return { checked: { type: Boolean, reflect: true }, role: { type: String, reflect: true }, + invalid: { type: Boolean, reflect: true }, _value: { type: String }, }; } @@ -99,6 +100,16 @@ class TpCheckbox extends Inert(ControlState(FormElement(LitElement))) { } } + validate() { + if (this.required && !this.checked) { + this.invalid = true; + return false; + } + + this.invalid = false; + return true; + } + get value() { if (this._value !== '') { return this._value;