Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract component validation class names to CssClassNames #1023

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.ICssClassNameProvider;
import de.agilecoders.wicket.core.util.Attributes;
import de.agilecoders.wicket.core.util.Components;
import de.agilecoders.wicket.core.util.CssClassNames;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.AttributeAppender;
Expand All @@ -22,6 +24,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static de.agilecoders.wicket.core.util.CssClassNames.Form.controlStateInvalid;
import static de.agilecoders.wicket.core.util.CssClassNames.Form.controlStateValid;
import static de.agilecoders.wicket.core.util.CssClassNames.Form.group;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -169,7 +175,7 @@ protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);

checkComponentTag(tag, "div");
Attributes.addClass(tag, "form-group");
Attributes.addClass(tag, group);
}

@Override
Expand Down Expand Up @@ -240,16 +246,13 @@ protected void onConfigure() {
stateClassName = "";
feedback.setDefaultModelObject("");

String validComponentClass = "is-valid";
String invalidComponentClass = "is-invalid";

final List<FormComponent<?>> formComponents = findFormComponents();

formComponents.forEach(c -> c.add(new Behavior() {
@Override
public void onComponentTag(Component component, ComponentTag tag)
{
Attributes.removeClass(tag, validComponentClass, invalidComponentClass);
Attributes.removeClass(tag, controlStateValid, controlStateInvalid);
}

@Override
Expand All @@ -273,9 +276,9 @@ public boolean isTemporary(Component component) {
public void onComponentTag(Component component, ComponentTag tag)
{
if(FeedbackMessageToCssClassNameTransformer.INVALID_FEEDBACK.equals(stateClassName))
Attributes.addClass(tag, invalidComponentClass);
Attributes.addClass(tag, controlStateInvalid);
else
Attributes.addClass(tag, validComponentClass);
Attributes.addClass(tag, controlStateValid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public static final class Form {
public static final String form = "form";
public static final String formRow = "form-row";
public static final String control = "form-control";
public static final String controlStateValid = "is-valid";
public static final String controlStateInvalid = "is-invalid";
public static final String label = "col-form-label";
public static final String staticControl = "form-control-static";
public static final String feedbackControl = "form-control-feedback";
Expand Down