Skip to content

Commit

Permalink
Add NodeNameValidator only to textFields named jcrName
Browse files Browse the repository at this point in the history
 - Validator is limited to string
 - All other fields don't have user input and don't need to be validated anyway e.g. option field
  • Loading branch information
eschleb committed Apr 8, 2024
1 parent e5474ef commit cabb72c
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import info.magnolia.ui.dialog.actions.OpenDialogActionDefinition;
import info.magnolia.ui.editor.LocaleContext;
import info.magnolia.ui.editor.validator.NodeNameValidatorDefinition;
import info.magnolia.ui.field.ConfiguredFieldDefinition;
import info.magnolia.ui.field.TextFieldDefinition;

import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -84,11 +84,11 @@ protected void addNodeNameValidatorToJcrNameField(final DialogDefinition dialogD
Optional
.of(dialogDefinition)
.filter(FormDialogDefinition.class::isInstance)
.map(definition -> (FormDialogDefinition<Node>) definition)
.map(definition -> (FormDialogDefinition<?>) definition)
.map(FormDialogDefinition::getForm)
.flatMap(formDialog -> formDialog.getFieldDefinition("jcrName"))
.filter(ConfiguredFieldDefinition.class::isInstance)
.map(definition -> (ConfiguredFieldDefinition<Node>) definition)
.filter(TextFieldDefinition.class::isInstance)
.map(definition -> (TextFieldDefinition) definition) // NodeNameValidator only validates string fields
.filter(field -> field.getValidators().stream().map(Object::getClass).noneMatch(NodeNameValidatorDefinition.class::equals))
.ifPresent(field ->
field.setValidators(Stream.concat(
Expand Down

0 comments on commit cabb72c

Please sign in to comment.