Skip to content

Commit

Permalink
MID-8147: fix for updating of autocomplete field
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Oct 4, 2022
1 parent 780aff6 commit 5ea6615
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import javax.xml.namespace.QName;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.convert.IConverter;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteTextPanel;
Expand Down Expand Up @@ -85,6 +87,12 @@ public void setObject(DisplayableValue<T> object) {
return new AutoCompleteTextPanel<>(panelCtx.getComponentId(), panelCtx.getRealValueModel(), panelCtx.getTypeClass(), false) {
@Override
public Iterator<T> getIterator(String input) {
if (StringUtils.isNotEmpty(input)) {
IConverter<T> converter = getConverter(panelCtx.getTypeClass());
return choices.stream()
.filter(choice -> converter.convertToString(choice, getLocale()).contains(input))
.collect(Collectors.toList()).iterator();
}
return choices.iterator();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.evolveum.midpoint.web.component.message.FeedbackAlerts;
import com.evolveum.midpoint.web.component.prism.InputPanel;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand All @@ -24,6 +25,7 @@

public class VerticalFormPrismPropertyValuePanel<T> extends PrismPropertyValuePanel<T> {

private final static String INVALID_FIELD_CLASS = "is-invalid";

public VerticalFormPrismPropertyValuePanel(String id, IModel<PrismPropertyValueWrapper<T>> model, ItemPanelSettings settings) {
super(id, model, settings);
Expand All @@ -37,7 +39,7 @@ protected void onInitialize() {
FormComponent baseFormComponent = ((InputPanel) valuePanel).getBaseFormComponent();
baseFormComponent.add(AttributeAppender.append("class", () -> {
if (baseFormComponent.hasErrorMessage()) {
return "is-invalid";
return INVALID_FIELD_CLASS;
}
return "";
}));
Expand Down Expand Up @@ -72,7 +74,10 @@ protected AjaxEventBehavior createEventBehavior() {

@Override
protected void onUpdate(AjaxRequestTarget target) {
updateFeedbackPanel(target);
String cssClass = getCssClassForValueContainer();
if (StringUtils.isNotEmpty(cssClass) && cssClass.contains(INVALID_FIELD_CLASS)) {
updateFeedbackPanel(target);
}
}

@Override
Expand Down

0 comments on commit 5ea6615

Please sign in to comment.