You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2022/06/07 03:06:29 UTC
[tapestry-5] branch master updated: TAP5-2714: wrong CSS class for Checkbox and Label with Boostrap 4
This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/master by this push:
new 99b96884b TAP5-2714: wrong CSS class for Checkbox and Label with Boostrap 4
99b96884b is described below
commit 99b96884b823cd43b99b1e328d293c9dce410022
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Tue Jun 7 00:06:17 2022 -0300
TAP5-2714: wrong CSS class for Checkbox and Label with Boostrap 4
---
.../tapestry5/corelib/components/Checkbox.java | 23 ++++++++++++++++++++--
.../apache/tapestry5/corelib/components/Label.java | 20 +++++++++++++------
.../test/app1/ValidateCheckboxMustBeUnchecked.tml | 8 ++++++--
3 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checkbox.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checkbox.java
index 1492ff96e..1a26ac893 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checkbox.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Checkbox.java
@@ -21,6 +21,10 @@ import org.apache.tapestry5.annotations.Mixin;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.corelib.base.AbstractField;
import org.apache.tapestry5.corelib.mixins.RenderDisabled;
+import org.apache.tapestry5.dom.Element;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.compatibility.Compatibility;
+import org.apache.tapestry5.services.compatibility.Trait;
/**
* A Checkbox component is simply a <input type="checkbox">.
@@ -41,12 +45,20 @@ public class Checkbox extends AbstractField
* generally used to provide this object in a declarative fashion.
*/
@Parameter(defaultPrefix = BindingConstants.VALIDATE, allowNull = false)
- @SuppressWarnings("unchecked")
private FieldValidator<Object> validate;
- @SuppressWarnings("unused")
@Mixin
private RenderDisabled renderDisabled;
+
+ @Inject
+ private Compatibility compatibility;
+
+ private boolean bootstrap4;
+
+ void pageLoaded()
+ {
+ bootstrap4 = compatibility.enabled(Trait.BOOTSTRAP_4);
+ }
@BeginRender
void begin(MarkupWriter writer)
@@ -68,6 +80,13 @@ public class Checkbox extends AbstractField
resources.renderInformalParameters(writer);
+ if (bootstrap4)
+ {
+ final Element element = writer.getElement();
+ String classAttribute = element.getAttribute("class");
+ classAttribute = classAttribute != null ? "form-check-input " + classAttribute : "form-check-input";
+ element.forceAttributes("class", classAttribute);
+ }
decorateInsideField();
}
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
index 6dd403af2..c64853a38 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
@@ -22,6 +22,8 @@ import org.apache.tapestry5.http.TapestryHttpSymbolConstants;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.services.compatibility.Compatibility;
+import org.apache.tapestry5.services.compatibility.Trait;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
/**
@@ -78,18 +80,24 @@ public class Label
*/
@Parameter
private boolean ignoreBody;
+
+ @Inject
+ private Compatibility compatibility;
private Element labelElement;
-
- private String string;
-
- private String string2;
+
+ private String cssClass;
+
+ void pageLoaded()
+ {
+ cssClass = compatibility.enabled(Trait.BOOTSTRAP_4) ? "form-check-label" : "control-label";
+ }
boolean beginRender(MarkupWriter writer)
{
decorator.beforeLabel(field);
-
- labelElement = writer.element("label", "class", "control-label");
+
+ labelElement = writer.element("label", "class", cssClass);
resources.renderInformalParameters(writer);
diff --git a/tapestry-core/src/test/app1/ValidateCheckboxMustBeUnchecked.tml b/tapestry-core/src/test/app1/ValidateCheckboxMustBeUnchecked.tml
index ae7b63995..143169f91 100644
--- a/tapestry-core/src/test/app1/ValidateCheckboxMustBeUnchecked.tml
+++ b/tapestry-core/src/test/app1/ValidateCheckboxMustBeUnchecked.tml
@@ -1,7 +1,11 @@
<html t:type="border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<t:form>
- <t:Checkbox value="value" validate="unchecked" />
+ <t:Checkbox t:id="checkbox" value="value" validate="unchecked"/>
+ <t:label for="checkbox">Checkbox must be unchecked</t:label>
+ <p/>
<t:submit/>
</t:form>
-Checkbox's value: ${value}
+<p>
+ Checkbox's value: ${value}
+</p>
</html>