File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class FieldBuilder implements FieldBuilderInterface {
1111
1212 public build ( field : HTMLElement , type : string ) : FieldInterface {
1313 if ( ! this . validateRequiredAttributes ( field ) ) {
14- console . error ( 'Field name and conditional is required' ) ;
14+ console . error ( 'Field name and conditional logic are required' ) ;
1515 return this . buildNullField ( field , type ) ;
1616 }
1717
@@ -46,7 +46,13 @@ class FieldBuilder implements FieldBuilderInterface {
4646 }
4747
4848 private getFieldName ( field : HTMLElement ) : string {
49- return field . getAttribute ( 'data-js-field-name' ) as string ;
49+ const name = field . getAttribute ( 'data-js-field-name' ) ;
50+ if ( ! name ) {
51+ console . error ( 'Field is missing data-js-field-name attribute' ) ;
52+ return 'unknown' ;
53+ }
54+
55+ return name ;
5056 }
5157
5258 private getFieldCondition ( field : HTMLElement ) : any {
@@ -64,14 +70,15 @@ class FieldBuilder implements FieldBuilderInterface {
6470 }
6571
6672 private validateRequiredAttributes ( field : HTMLElement ) : boolean {
67- [ this . name , this . condition ] . forEach ( ( attribute ) => {
73+ const isValid = [ this . name , this . condition ] . every ( ( attribute ) => {
6874 if ( ! field . getAttribute ( attribute ) ) {
6975 console . error ( `Field is missing required attribute: ${ attribute } ` ) ;
7076 return false ;
7177 }
78+ return true ;
7279 } ) ;
7380
74- return true ;
81+ return isValid ;
7582 }
7683}
7784
You can’t perform that action at this time.
0 commit comments