@@ -6,15 +6,22 @@ import { property, query } from 'lit/decorators.js';
6
6
export class BlrFormExampleWithoutSlot extends LitElement {
7
7
@property ( ) theme : ThemeType = 'Light' ;
8
8
@property ( ) firstInputValue : string = '' ;
9
+ @property ( ) firstTextInputHasError : boolean = false ;
10
+ @property ( ) secondTextInputHasError : boolean = false ;
11
+ @property ( ) radioHasError : boolean = false ;
9
12
@property ( ) secondInputValue : string = '' ;
10
- @property ( ) errorMessage : string = '' ;
11
- @property ( ) firstNameHasError ?: boolean = false ;
12
- @property ( ) lastNameHasError ?: boolean = false ;
13
- @property ( { reflect : true } ) checkBoxChecked : boolean = false ;
13
+ @property ( ) checkInputHasError ?: boolean = false ;
14
+ @property ( ) selectHasError ?: boolean = false ;
15
+ @property ( ) checkBoxChecked : boolean = false ;
16
+ @property ( ) textInputErrorMessage : string = 'input field required' ;
17
+ @property ( ) selectErrorMessage : string = 'at least one selection required' ;
18
+ @property ( ) radioErrorMessage : string = 'at least one selection required' ;
14
19
15
20
@query ( 'blr-text-input[name="firstInput"]' ) firstInputElement ! : HTMLElement ;
16
21
@query ( 'blr-text-input[name="secondInput"]' ) secondInputElement ! : HTMLElement ;
17
22
@query ( 'blr-checkbox[name="checkInput"]' ) checkboxInputElement ! : HTMLElement ;
23
+ @query ( 'blr-select[name="select"]' ) selectElement ! : HTMLElement ;
24
+ @query ( 'blr-radio[name="radio"]' ) radioElement ! : HTMLElement ;
18
25
19
26
protected render ( ) {
20
27
return html `
@@ -36,6 +43,8 @@ export class BlrFormExampleWithoutSlot extends LitElement {
36
43
showinputicon ="true "
37
44
@blrTextValueChange ="${ this . handleFirstInputChange } "
38
45
required ="true "
46
+ .hasError =${ this . firstTextInputHasError }
47
+ errorMessage =${ this . textInputErrorMessage }
39
48
> </ blr-text-input >
40
49
< blr-text-input
41
50
size ="md "
@@ -53,23 +62,59 @@ export class BlrFormExampleWithoutSlot extends LitElement {
53
62
inputicon ="blr360 "
54
63
showinputicon ="true "
55
64
@blrTextValueChange ="${ this . handleSecondInputChange } "
65
+ .hasError =${ this . secondTextInputHasError }
66
+ errorMessage =${ this . textInputErrorMessage }
56
67
required="true"
57
68
> </ blr-text-input >
69
+ < blr-select
70
+ theme ="Light "
71
+ size ="md "
72
+ label ="Select one "
73
+ labelappendix =""
74
+ icon =""
75
+ hinticon ="blrInfo "
76
+ .hasError =${ this . selectHasError }
77
+ errormessage =${ this . selectErrorMessage }
78
+ errormessageicon="blrError"
79
+ arialabel="Select"
80
+ selectid="selectId"
81
+ name="select"
82
+ haslabel="true"
83
+ required="true"
84
+ >
85
+ < option value ="" label ="--Please choose an option-- "> </ option >
86
+ < option value ="option1 " label ="Option 1 "> </ option >
87
+ < option value ="option2 " label ="Option 2 "> </ option >
88
+ </ blr-select >
89
+ < blr-radio
90
+ theme ="Light "
91
+ size ="md "
92
+ value =""
93
+ label ="Hint and error message "
94
+ .hasError =${ this . radioHasError }
95
+ errormessage =${ this . radioErrorMessage }
96
+ arialabel=""
97
+ erroricon="blrErrorFilled"
98
+ optionid="optionId"
99
+ name="radio"
100
+ required="true"
101
+ > </ blr-radio >
58
102
< blr-checkbox
59
103
theme ="Light "
60
104
size ="md "
61
105
checkedicon ="blrCheckmark "
62
106
indeterminatedicon ="blrMinus "
63
107
haslabel ="true "
64
108
label ="I accept the terms and conditions. "
65
- hintmessage ="This is a small hint message "
66
- hinticon ="blrInfo "
67
109
erroricon =""
68
110
arialabel ="check Input "
69
111
checkinputid ="checkInputId "
70
112
name ="checkInput "
71
113
@blrCheckedChange =${ this . handleCheckInput }
72
- ?checked =${ this . checkBoxChecked }
114
+ .hasError =${ this . checkInputHasError }
115
+ errorMessage="must be checked"
116
+ required="true"
117
+ .checked=${ this . checkBoxChecked }
73
118
> </ blr-checkbox >
74
119
< blr-text-button
75
120
theme ="Light "
@@ -88,52 +133,41 @@ export class BlrFormExampleWithoutSlot extends LitElement {
88
133
89
134
private handleSubmit ( event ) {
90
135
event . preventDefault ( ) ;
136
+ const shadowFirstInputElement = this . firstInputElement . shadowRoot ?. querySelector ( 'input[name="firstInput"]' ) ;
137
+ const shadowSecondInputElement = this . secondInputElement . shadowRoot ?. querySelector ( 'input[name="secondInput"]' ) ;
138
+ const shadowCheckInputElement = this . checkboxInputElement . shadowRoot ?. querySelector ( 'input[name="checkInput"]' ) ;
139
+ const shadowSelectElement = this . selectElement . shadowRoot ?. querySelector ( 'select[name="select"]' ) ;
140
+ const shadowRadioElement = this . radioElement . shadowRoot ?. querySelector ( 'input[name="radio"]' ) ;
91
141
92
- if (
93
- ( this . secondInputElement . hasAttribute ( 'required' ) && this . secondInputValue . trim ( ) === '' ) ||
94
- ( this . secondInputElement . hasAttribute ( 'required' ) && this . secondInputValue . trim ( ) === '' ) ||
95
- ! this . checkboxInputElement . hasAttribute ( 'checked' )
96
- ) {
97
- if ( this . firstInputElement . hasAttribute ( 'required' ) && this . firstInputValue . trim ( ) === '' ) {
98
- this . firstInputElement . _onPropChanged ( {
99
- detail : {
100
- hasError : true ,
101
- errorMessage : 'This is a required field' ,
102
- } ,
103
- } ) ;
104
- }
105
-
106
- if ( this . secondInputElement . hasAttribute ( 'required' ) && this . secondInputValue . trim ( ) === '' ) {
107
- this . secondInputElement . _onPropChanged ( {
108
- detail : {
109
- hasError : true ,
110
- errorMessage : 'This is a required field' ,
111
- } ,
112
- } ) ;
113
- }
114
-
115
- if ( ! this . checkboxInputElement . hasAttribute ( 'checked' ) ) {
116
- this . checkboxInputElement . _onPropChanged ( {
117
- detail : {
118
- hasError : true ,
119
- errorMessage : 'This is a required field' ,
120
- } ,
121
- } ) ;
122
- }
123
- console . log ( 'Please provide a value for both first input and last input fields and check the checkbox.' ) ;
124
- // just to simulate the value change. Remove later
125
- setTimeout ( ( ) => {
126
- this . dispatchEvent (
127
- new CustomEvent ( 'propChanged' , {
128
- detail : { hasError : false , errorMessage : '' } ,
129
- bubbles : true ,
130
- composed : true ,
131
- } )
132
- ) ;
133
- } , 3000 ) ;
134
- return ;
142
+ if ( ! shadowFirstInputElement ?. checkValidity ( ) ) {
143
+ this . firstTextInputHasError = true ;
135
144
}
136
145
146
+ if ( ! shadowSecondInputElement ?. checkValidity ( ) ) {
147
+ this . secondTextInputHasError = true ;
148
+ }
149
+
150
+ if ( ! shadowCheckInputElement ?. checkValidity ( ) ) {
151
+ this . checkInputHasError = true ;
152
+ }
153
+
154
+ if ( ! shadowSelectElement ?. checkValidity ( ) ) {
155
+ this . selectHasError = true ;
156
+ }
157
+
158
+ if ( ! shadowRadioElement ?. checkValidity ( ) ) {
159
+ this . radioHasError = true ;
160
+ }
161
+
162
+ // just to simulate the value change. Remove later
163
+ setTimeout ( ( ) => {
164
+ this . firstTextInputHasError = false ;
165
+ this . secondTextInputHasError = false ;
166
+ this . checkInputHasError = false ;
167
+ this . selectHasError = false ;
168
+ this . radioHasError = false ;
169
+ } , 2000 ) ;
170
+
137
171
console . log (
138
172
`First Input: ${ this . firstInputValue } , Second Input: ${ this . secondInputValue } , checkbox checked: ${ this . checkBoxChecked } `
139
173
) ;
0 commit comments