@@ -2,7 +2,11 @@ import * as _ from "lodash-es";
2
2
import { html , LitElement , TemplateResult } from "lit" ;
3
3
import { property , state , query } from "lit/decorators.js" ;
4
4
import { repeat } from "lit/directives/repeat.js" ;
5
- import { renderInTooltip , noKeyWarning } from "./utils.js" ;
5
+ import {
6
+ renderInTooltip ,
7
+ noKeyWarning ,
8
+ findNearestFormGroup ,
9
+ } from "./utils.js" ;
6
10
import "@shoelace-style/shoelace/dist/components/alert/alert.js" ;
7
11
import "@shoelace-style/shoelace/dist/components/icon/icon.js" ;
8
12
import "@shoelace-style/shoelace/dist/components/input/input.js" ;
@@ -54,7 +58,7 @@ export default class EccUtilsDesignFormInput extends LitElement {
54
58
@state ( ) private alertText = "Something went wrong" ;
55
59
@state ( ) private alertType : AlertType = "info" ;
56
60
@state ( ) private showAlert = false ;
57
- @state ( ) path = "" ;
61
+ @state ( ) path : string | null = "" ;
58
62
59
63
@query ( "sl-input" ) input ! : HTMLInputElement ;
60
64
@@ -63,38 +67,14 @@ export default class EccUtilsDesignFormInput extends LitElement {
63
67
if ( ! this . key ) {
64
68
noKeyWarning ( "ecc-d-form-group" , this . label ) ;
65
69
this . key = _ . camelCase ( this . label ) ;
70
+ this . setAttribute ( "key" , this . key ) ;
66
71
}
67
72
68
- this . findNearestFormGroup ( ) ;
73
+ this . path = findNearestFormGroup ( this . key , this ) ;
69
74
70
75
if ( this . value ) {
71
76
this . handleFireChangeEvent ( ) ;
72
77
}
73
-
74
- // console.log("just connected");
75
- }
76
-
77
- private findNearestFormGroup ( element : HTMLElement | null = this ) : void {
78
- if ( ! element ) return ;
79
-
80
- if ( element . matches ( "ecc-d-form" ) || element . matches ( "ecc-d-form-group" ) ) {
81
- return ;
82
- }
83
-
84
- const { parentElement } = element ;
85
- if ( ! parentElement ) return ;
86
-
87
- const specialAttributes = [ "ecc-array" , "ecc-group" , "ecc-form" ] ;
88
- const hasSpecialAttribute = specialAttributes . some ( ( attr ) =>
89
- parentElement . hasAttribute ( attr )
90
- ) ;
91
-
92
- if ( hasSpecialAttribute ) {
93
- const parentPath = parentElement . getAttribute ( "path" ) ;
94
- this . path = parentPath ? `${ parentPath } .${ this . key } ` : this . key ;
95
- }
96
-
97
- this . findNearestFormGroup ( parentElement ) ;
98
78
}
99
79
100
80
private handleDismissAlert ( ) {
@@ -140,8 +120,6 @@ export default class EccUtilsDesignFormInput extends LitElement {
140
120
const target = e . target as HTMLInputElement ;
141
121
this . value = this . type === "switch" ? target . checked : target . value ;
142
122
143
- console . log ( "this.value" , this . value , target ) ;
144
-
145
123
this . handleFireChangeEvent ( ) ;
146
124
this . requestUpdate ( ) ;
147
125
}
0 commit comments