Add validation logic
This commit is contained in:
parent
dcfb3641bb
commit
b17f9b4aec
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tp/tp-checkbox",
|
"name": "@tp/tp-checkbox",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "tp-checkbox.js",
|
"main": "tp-checkbox.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -72,6 +72,7 @@ class TpCheckbox extends Inert(ControlState(FormElement(LitElement))) {
|
|||||||
return {
|
return {
|
||||||
checked: { type: Boolean, reflect: true },
|
checked: { type: Boolean, reflect: true },
|
||||||
role: { type: String, reflect: true },
|
role: { type: String, reflect: true },
|
||||||
|
invalid: { type: Boolean, reflect: true },
|
||||||
_value: { type: String },
|
_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() {
|
get value() {
|
||||||
if (this._value !== '') {
|
if (this._value !== '') {
|
||||||
return this._value;
|
return this._value;
|
||||||
|
Loading…
Reference in New Issue
Block a user