14
14
use ipl \Html \FormElement \FieldsetElement ;
15
15
use ipl \Html \FormElement \SelectElement ;
16
16
use ipl \Html \FormElement \SubmitButtonElement ;
17
+ use ipl \Validator \CallbackValidator ;
17
18
use ipl \Web \Widget \Icon ;
18
19
19
20
class EscalationRecipient extends FieldsetElement
@@ -62,7 +63,7 @@ protected function assemble(): void
62
63
'select ' ,
63
64
'column_ ' . $ i ,
64
65
[
65
- 'class ' => ['autosubmit ' , ' left-operand ' ],
66
+ 'class ' => ['left-operand ' ],
66
67
'options ' => [
67
68
'' => sprintf (' - %s - ' , $ this ->translate ('Please choose ' ))
68
69
] + $ this ->fetchOptions (),
@@ -73,46 +74,45 @@ protected function assemble(): void
73
74
);
74
75
75
76
$ this ->registerElement ($ col );
77
+ /** @var string $recipientVal */
78
+ $ recipientVal = $ this ->getValue ('column_ ' . $ i ) ?? '' ;
79
+ $ recipient = explode ('_ ' , $ recipientVal );
76
80
77
- $ options = ['' => sprintf (' - %s - ' , $ this ->translate ('Please choose ' ))];
81
+ $ options = ['' => sprintf ('%s ' , $ this ->translate ('Default User Channel ' ))];
78
82
$ options += Channel::fetchChannelNames (Database::get ());
79
83
80
84
/** @var SelectElement $val */
81
85
$ val = $ this ->createElement (
82
86
'select ' ,
83
87
'val_ ' . $ i ,
84
88
[
85
- 'class ' => ['autosubmit ' , ' right-operand ' ],
89
+ 'class ' => ['right-operand ' ],
86
90
'options ' => $ options ,
87
91
'disabledOptions ' => ['' ],
88
- 'value ' => $ this ->getPopulatedValue ('val_ ' . $ i )
92
+ 'value ' => $ this ->getPopulatedValue ('val_ ' . $ i ),
93
+ 'validators ' => [
94
+ new CallbackValidator (function ($ value , $ validator ) use ($ recipient ) {
95
+ if ($ recipient [0 ] !== 'contact ' && $ value !== '' ) {
96
+ $ validator ->addMessage (
97
+ $ this ->translate (
98
+ 'The channel cannot be the default channel for the recipient type '
99
+ . $ recipient [0 ]
100
+ )
101
+ );
102
+
103
+ return false ;
104
+ }
105
+
106
+ $ validator ->clearMessages ();
107
+ return true ;
108
+ })
109
+ ]
89
110
]
90
111
);
91
112
92
- /** @var string $recipientVal */
93
- $ recipientVal = $ this ->getValue ('column_ ' . $ i );
94
- if ($ recipientVal !== null ) {
95
- $ recipient = explode ('_ ' , $ recipientVal );
96
- if ($ recipient [0 ] === 'contact ' ) {
97
- $ options ['' ] = $ this ->translate ('Default User Channel ' );
98
-
99
- $ val ->setOptions ($ options );
100
-
101
- $ val ->setDisabledOptions ([]);
113
+ $ val ->setDisabledOptions ([]);
102
114
103
- if ($ this ->getPopulatedValue ('val_ ' . $ i , '' ) === '' ) {
104
- $ val ->addAttributes (['class ' => 'default-channel ' ]);
105
- }
106
- }
107
- } else {
108
- /** @var BaseFormElement $val */
109
- $ val = $ this ->createElement ('text ' , 'val_ ' . $ i , [
110
- 'class ' => 'right-operand ' ,
111
- 'placeholder ' => $ this ->translate ('Please make a decision ' ),
112
- 'disabled ' => true ,
113
- 'value ' => $ this ->getPopulatedValue ('val_ ' . $ i )
114
- ]);
115
- }
115
+ $ val ->getOption ('' )->setAttribute ('class ' , 'default-channel ' );
116
116
117
117
$ this ->registerElement ($ val );
118
118
0 commit comments