File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,19 @@ class AndCondition implements ConditionInterface {
33 }
44
55 public validate ( ) : boolean {
6+ let isValid : boolean [ ] = [ ] ;
7+ this . conditions . forEach ( condition => {
8+ if ( ! condition . class ) {
9+ return ;
10+ }
11+
12+ isValid . push ( condition . class . getConditionValidator ( ) . validate ( condition ) ) ;
13+ } ) ;
14+
15+ if ( isValid . includes ( false ) ) {
16+ return false ;
17+ }
18+
619 return true ;
720 }
821
Original file line number Diff line number Diff line change @@ -3,8 +3,7 @@ class OrCondition implements ConditionInterface {
33 }
44
55 public validate ( ) : boolean {
6- // Implement validation logic
7- return true ;
6+ return this . condition . class ?. getConditionValidator ( ) . validate ( this . condition ) ?? true ;
87 }
98
109 public getConditions ( ) : Condition [ ] {
Original file line number Diff line number Diff line change @@ -8,10 +8,6 @@ interface ConditionInterface {
88 getConditionFieldNames ( ) : string [ ] ;
99}
1010
11- interface ConditionValidatorInterface {
12- validate ( condition : Condition ) : boolean ;
13- }
14-
1511type Condition = {
1612 field : string ;
1713 class : FieldInterface | null ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ class CheckboxConditionValidator implements ConditionValidatorInterface {
2+ public validate ( condition : Condition ) : boolean {
3+
4+ return false ;
5+ }
6+ }
7+
8+ export default CheckboxConditionValidator ;
Original file line number Diff line number Diff line change @@ -12,11 +12,6 @@ class CheckboxConditionsHandler implements ConditionsHandlerInterface {
1212 this . setValueChangeListener ( ) ;
1313 }
1414
15- public validateCondition ( conditions : Condition [ ] ) : boolean {
16- console . log ( conditions ) ;
17- return true ;
18- }
19-
2015 public validate ( ) : boolean {
2116 this . getConditions ( ) . forEach ( ( condition ) => {
2217 condition . validate ( ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ class NullField implements FieldInterface {
33 private field : HTMLElement ,
44 type : string ,
55 private name : string ,
6- private conditionsHandler : ConditionsHandlerInterface
6+ private nullFieldConditionValidator : ConditionValidatorInterface ,
7+ private conditionsHandler : ConditionsHandlerInterface ,
8+
79 ) {
810 console . error ( `Field type "${ type } " is not implemented.` ) ;
911 }
@@ -23,6 +25,10 @@ class NullField implements FieldInterface {
2325 public getConditionsHandler ( ) : ConditionsHandlerInterface {
2426 return this . conditionsHandler ;
2527 }
28+
29+ public getConditionValidator ( ) : ConditionValidatorInterface {
30+ return this . nullFieldConditionValidator ;
31+ }
2632}
2733
2834export default NullField ;
Original file line number Diff line number Diff line change 1+ class NullFieldConditionValidator implements ConditionValidatorInterface {
2+ public validate ( condition : Condition ) : boolean {
3+
4+ return false ;
5+ }
6+ }
7+
8+ export default NullFieldConditionValidator ;
Original file line number Diff line number Diff line change 11import Checkbox from "./field/checkbox/checkbox" ;
22import CheckboxConditionsHandler from "./field/checkbox/checkboxConditionsHandler" ;
3+ import CheckboxConditionValidator from "./field/checkbox/checkboxConditionValidator" ;
34import NullFieldConditionsHandler from "./field/nullField/nullFieldConditionsHandler" ;
45import NullField from "./field/nullField/nullField" ;
5- import CheckboxValidator from "../conditions/validate/checkboxValidator " ;
6+ import NullFieldConditionValidator from "./field/nullField/nullFieldConditionValidator " ;
67
78class FieldBuilder implements FieldBuilderInterface {
89 private name : string = 'data-js-field-name' ;
@@ -27,6 +28,7 @@ class FieldBuilder implements FieldBuilderInterface {
2728 field ,
2829 type ,
2930 this . getFieldName ( field ) ,
31+ new NullFieldConditionValidator ( ) ,
3032 new NullFieldConditionsHandler ( field , this . getFieldCondition ( field ) )
3133 ) ;
3234 }
@@ -38,7 +40,7 @@ class FieldBuilder implements FieldBuilderInterface {
3840 field ,
3941 choices ,
4042 this . getFieldName ( field ) ,
41- new CheckboxValidator ( ) ,
43+ new CheckboxConditionValidator ( ) ,
4244 new CheckboxConditionsHandler ( this . getFieldCondition ( field ) )
4345 ) ;
4446 }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ interface FieldInterface {
66 init ( conditionBuilder : ConditionBuilderInterface ) : void ;
77 getName ( ) : string ;
88 getConditionsHandler ( ) : ConditionsHandlerInterface ;
9+ getConditionValidator ( ) : ConditionValidatorInterface ;
910}
1011
1112interface CheckboxInterface extends FieldInterface {
@@ -24,6 +25,10 @@ interface ConditionsHandlerInterface {
2425 addValueChangeListener ( field : FieldInterface ) : void ;
2526}
2627
28+ interface ConditionValidatorInterface {
29+ validate ( condition : Condition ) : boolean ;
30+ }
31+
2732type FieldsObject = {
2833 [ key : string ] : FieldInterface ;
2934}
You can’t perform that action at this time.
0 commit comments