@@ -174,8 +174,15 @@ private function createValueFormElement($enrichmentValue, $enrichmentKey = null,
174
174
// vom Benutzer nicht verändert wurde)
175
175
$ elementValue = $ element ->getValue ();
176
176
$ isValidValue = false ;
177
- if (! ($ elementValue === false )) {
178
- $ isValidValue = $ element ->isValid ($ value );
177
+ if ($ elementValue !== false ) {
178
+ $ isValidValue = $ element ->isValid ($ value ); // TODO always needed because of side effects
179
+ if ($ enrichmentType ->getFormElementName () === 'Select ' ) {
180
+ $ values = $ enrichmentType ->getValues ();
181
+ $ isValidValue = in_array ($ value , $ values );
182
+ if ($ isValidValue ) {
183
+ $ element ->removeDecorator ('Errors ' );
184
+ }
185
+ }
179
186
180
187
// der Aufruf der isValid-Methode hat einen Seiteneffekt, der bei Select-Elementen
181
188
// zum Ersetzen des Index durch den tatsächlichen Wert führt
@@ -195,6 +202,23 @@ private function createValueFormElement($enrichmentValue, $enrichmentKey = null,
195
202
}
196
203
}
197
204
}
205
+ } else {
206
+ /* TODO show error message immediately if value cannot be saved (strict validation)
207
+ The message does not disappear right if another value is selected. The
208
+ Javascript in validation.js does not support 'errors', just 'datahint'.
209
+ */
210
+ if ($ enrichmentType ->getFormElementName () === 'Select ' ) {
211
+ $ values = $ enrichmentType ->getValues ();
212
+ if (! in_array ($ value , $ values )) {
213
+ $ this ->getElement (self ::ELEMENT_VALUE )->markAsError ();
214
+ $ element ->setAttrib ('data-opusValidationError ' , 'true ' ); // wird vom JavaScript-Code ausgewertet
215
+ }
216
+ } else {
217
+ if (! $ element ->isValid ($ value )) {
218
+ $ this ->getElement (self ::ELEMENT_VALUE )->markAsError ();
219
+ $ element ->setAttrib ('data-opusValidationError ' , 'true ' ); // wird vom JavaScript-Code ausgewertet
220
+ }
221
+ }
198
222
}
199
223
}
200
224
@@ -261,7 +285,7 @@ public function updateModel($enrichment)
261
285
// keine Behandlung von Enrichments, die noch nicht in der Datenbank gespeichert sind,
262
286
// (nach dem Hinzufügen von Enrichments über Hinzufügen-Button)
263
287
if (! in_array ($ enrichment ->getValue (), $ enrichmentType ->getValues ())) {
264
- if ($ enrichmentValue === 0 ) {
288
+ if (( int ) $ enrichmentValue === 0 ) {
265
289
return ; // keine Änderung des Enrichment-Werts
266
290
}
267
291
0 commit comments