Skip to content

Commit 9850302

Browse files
committed
refactor: fieldBuilder update
1 parent b0e6976 commit 9850302

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

source/js/fields/fieldBuilder.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)