@@ -51,6 +51,8 @@ protected function assemble(): void
5151 ['value ' => (string ) $ defaultCount ]
5252 );
5353
54+ $ this ->addElement ('hidden ' , 'remove-position ' );
55+
5456 $ addCondition = $ this ->createElement (
5557 'submitButton ' ,
5658 'add-condition ' ,
@@ -76,7 +78,6 @@ protected function assemble(): void
7678 for ($ i = 1 ; $ i <= $ conditionCount ; $ i ++) {
7779 $ colName = 'column_ ' . $ i ;
7880 $ opName = 'operator_ ' . $ i ;
79- $ typeName = 'type_ ' . $ i ;
8081 $ valName = 'val_ ' . $ i ;
8182
8283 $ col = $ this ->createElement (
@@ -126,18 +127,6 @@ protected function assemble(): void
126127 ]
127128 );
128129
129- if (
130- $ this ->getPopulatedValue ($ typeName ) !== 'incident_severity '
131- && $ this ->getPopulatedValue ($ valName ) !== null
132- ) {
133- $ this ->clearPopulatedValue ($ typeName );
134- $ this ->clearPopulatedValue ($ valName );
135- }
136-
137- $ this ->addElement ('hidden ' , $ typeName , [
138- 'value ' => 'incident_severity '
139- ]);
140-
141130 break ;
142131 case 'incident_age ' :
143132 $ val = $ this ->createElement (
@@ -166,18 +155,6 @@ protected function assemble(): void
166155 ]
167156 );
168157
169- if (
170- $ this ->getPopulatedValue ($ typeName ) !== 'incident_age '
171- && $ this ->getPopulatedValue ($ valName ) !== null
172- ) {
173- $ this ->clearPopulatedValue ($ typeName );
174- $ this ->clearPopulatedValue ($ valName );
175- }
176-
177- $ this ->addElement ('hidden ' , $ typeName , [
178- 'value ' => 'incident_age '
179- ]);
180-
181158 break ;
182159 default :
183160 $ val = $ this ->createElement ('text ' , $ valName , [
@@ -197,6 +174,7 @@ protected function assemble(): void
197174
198175 $ removePosition = (int ) $ this ->getValue ('remove ' );
199176 if ($ removePosition ) {
177+ $ this ->getElement ('remove-position ' )->setValue ($ removePosition );
200178 unset($ this ->conditions [$ removePosition ]);
201179 $ conditionCount -= 1 ;
202180 if ($ conditionCount === 1 && ! $ this ->allowZeroConditions && $ removePosition === 2 ) {
@@ -207,7 +185,7 @@ protected function assemble(): void
207185 $ this ->conditions [$ nextCount ]->conditionType ->setName ('column_ ' . $ n );
208186 $ this ->conditions [$ nextCount ]->operator ->setName ('operator_ ' . $ n );
209187 $ this ->conditions [$ nextCount ]->conditionVal ->setName ('val_ ' . $ n );
210- if ($ conditionCount === 1 ) {
188+ if ($ conditionCount === 1 && ! $ this -> allowZeroConditions ) {
211189 $ this ->conditions [$ nextCount ]->removeButton = null ;
212190 } elseif ($ this ->conditions [$ nextCount ]->removeButton ) {
213191 $ this ->conditions [$ nextCount ]->removeButton ->setValue ((string ) $ n );
@@ -275,9 +253,17 @@ public function getCondition(): string
275253 $ filter = Filter::any ();
276254 /** @var int $count */
277255 $ count = $ this ->getValue ('condition-count ' );
256+ $ removePosition = $ this ->getValue ('remove-position ' );
257+ if ($ removePosition ) {
258+ $ count += 1 ;
259+ }
278260
279261 if ($ count > 0 ) { // if count is 0, loop runs in reverse direction
280262 foreach (range (1 , $ count ) as $ count ) {
263+ if ($ count === (int ) $ removePosition ) {
264+ continue ;
265+ }
266+
281267 $ chosenType = $ this ->getValue ('column_ ' . $ count , 'placeholder ' );
282268
283269 $ filterStr = $ chosenType
0 commit comments