@@ -7,6 +7,13 @@ import Type from '../../rb-base/scripts/type-service.js';
77import template from '../views/rb-checkbox.html' ;
88
99export class RbCheckbox extends FormControl ( RbBase ( ) ) {
10+
11+ constructor ( ) {
12+ super ( ) ;
13+ this . state = {
14+ value : undefined
15+ }
16+ }
1017 /* Lifecycle
1118 ************/
1219 viewReady ( ) { // :void
@@ -40,12 +47,13 @@ export class RbCheckbox extends FormControl(RbBase()) {
4047 case / ^ { [ ^ ] * } $ / . test ( val ) : // object
4148 newVal = JSON . parse ( val ) ;
4249 break ;
43- case / ^ - ? \d * \. ? \d * $ / . test ( val ) : //number
50+ case / ^ - ? \d * \. ? \d * $ / . test ( val ) : // number
4451 newVal = parseFloat ( val )
4552 break ;
4653 default : // string
4754 newVal = val ;
4855 }
56+
4957 return newVal ;
5058 }
5159 } )
@@ -59,8 +67,10 @@ export class RbCheckbox extends FormControl(RbBase()) {
5967 return code . toLowerCase ( ) ;
6068 }
6169 async setValue ( value ) { // :void
62- this . value = ! value ;
63- // await this.validate();
70+ if ( this . value === undefined || this . state . value === undefined ) return this . value = true ;
71+ if ( typeof ( value ) === 'boolean' ) return this . value = ! value ;
72+ if ( ! ! this . value ) return this . value = null ;
73+ this . value = this . state . value ;
6474 }
6575
6676 /* Observer
@@ -72,10 +82,17 @@ export class RbCheckbox extends FormControl(RbBase()) {
7282 } ) ;
7383 }
7484
85+ updated ( prevProps , prevState ) {
86+ super . updated && super . updated ( prevProps , prevState ) ;
87+ if ( ! ! this . state . value ) return ;
88+ this . state . value = this . value ;
89+ }
90+
7591 /* Event Handlers
7692 *****************/
77- _onclick ( value , evt ) { // :void
93+ async _onclick ( value , evt ) { // :void
7894 this . setValue ( value ) ;
95+ await this . validate ( )
7996 }
8097 _onkeypress ( value , evt ) { // :void
8198 const keys = [ 'enter' , 'space' ] ;
0 commit comments