You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2018/08/28 10:57:13 UTC

[myfaces-tobago] 01/02: TOBAGO-1922 Required style not set for tc:label

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit cc3819e8442f58151d00b085eccc5512e02d6b25
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Tue Aug 28 11:53:21 2018 +0200

    TOBAGO-1922 Required style not set for tc:label
    
    * required CSS class is now set for tc:label if using 'for'
    * a red * appears if CSS class 'tobago-required' is set on a label
    * tests added
    * demo for tc:label improved
---
 .../internal/renderkit/renderer/LabelRenderer.java |  7 ++
 tobago-core/src/main/resources/scss/_tobago.scss   |  3 +-
 .../20-component/020-output/20-label/label.xhtml   | 11 ++-
 .../1500-output/21-label-for/label-for.test.js     | 48 +++++++++++++
 .../1500-output/21-label-for/label-for.xhtml       | 84 ++++++++++++++++++++++
 .../content/40-test/1500-output/output.xhtml       | 24 +++++++
 6 files changed, 175 insertions(+), 2 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/LabelRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/LabelRenderer.java
index 859b9c1..d1bfd10 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/LabelRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/LabelRenderer.java
@@ -66,12 +66,19 @@ public class LabelRenderer extends RendererBase implements ComponentSystemEventL
     }
     final String clientId = label.getClientId(facesContext);
     final Markup markup = label.getMarkup();
+    final boolean required;
+    if (corresponding instanceof UIInput) {
+      required = ((UIInput) corresponding).isRequired();
+    } else {
+      required = false;
+    }
 
     writer.startElement(HtmlElements.LABEL);
     HtmlRendererUtils.writeDataAttributes(facesContext, writer, label);
     writer.writeClassAttribute(
         TobagoClass.LABEL,
         TobagoClass.LABEL.createMarkup(markup),
+        required ? TobagoClass.REQUIRED : null,
         BootstrapClass.COL_FORM_LABEL,
         label.getCustomClass());
     writer.writeIdAttribute(clientId);
diff --git a/tobago-core/src/main/resources/scss/_tobago.scss b/tobago-core/src/main/resources/scss/_tobago.scss
index ec9bb42..2732a4a 100644
--- a/tobago-core/src/main/resources/scss/_tobago.scss
+++ b/tobago-core/src/main/resources/scss/_tobago.scss
@@ -1545,7 +1545,8 @@ fixme: there is a problem with the selectManyShuttle with this style.
   display: none;
 }
 
-.tobago-required .tobago-label:after {
+.tobago-required .tobago-label:after,
+.tobago-required.tobago-label:after {
   content: "*";
   color: theme-color("danger");
 }
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/20-label/label.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/20-label/label.xhtml
index 67ec01d..fec6e6b 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/20-label/label.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/020-output/20-label/label.xhtml
@@ -25,12 +25,21 @@
   <p>With <code class="language-markup">&lt;tc:label/></code>, a single label can be created.
     Some components already have a <code>label</code> attribute to combine it with a label,
     which should be used in general.</p>
-  <tc:link label="Tag Library Documentation" image="#{request.contextPath}/image/feather-leaf.png" link="#{demoBundle.tagDocUrl}/#{info.stableVersion}/tld/tc/label.html"/>
+  <tc:link label="Tag Library Documentation" image="#{request.contextPath}/image/feather-leaf.png"
+           link="#{demoBundle.tagDocUrl}/#{info.stableVersion}/tld/tc/label.html"/>
   <tc:section label="Basics">
     <pre><code class="language-markup">&lt;tc:label value="Single Label"/&gt;</code></pre>
     <tc:label id="l1" value="Single Label"/>
   </tc:section>
 
+  <tc:section label="for-attribute">
+    <p>A label can be linked to a component using the <code>for</code> attribute.</p>
+    <tc:segmentLayout medium="3seg 9seg">
+      <tc:label for="inputField" value="Required"/>
+      <tc:in id="inputField" required="true"/>
+    </tc:segmentLayout>
+  </tc:section>
+
   <tc:section label="Input Field">
     <p>With <code class="language-markup">&lt;tc:flexLayout columns="250px 1fr 200px"></code> a label is set
       in front and after an inputfield. The <code>label</code> attribute is not used for
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/21-label-for/label-for.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/21-label-for/label-for.test.js
new file mode 100644
index 0000000..df622d8
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/21-label-for/label-for.test.js
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+QUnit.test("Test for required CSS class", function (assert) {
+  assert.expect(13);
+
+  var $inLabel = jQueryFrame("#page\\:mainForm\\:inLabel");
+  var $dateLabel = jQueryFrame("#page\\:mainForm\\:dateLabel");
+  var $fileLabel = jQueryFrame("#page\\:mainForm\\:fileLabel");
+  var $textareaLabel = jQueryFrame("#page\\:mainForm\\:textareaLabel");
+  var $selectBooleanCheckboxLabel = jQueryFrame("#page\\:mainForm\\:selectBooleanCheckboxLabel");
+  var $selectBooleanToggleLabel = jQueryFrame("#page\\:mainForm\\:selectBooleanToggleLabel");
+  var $selectOneRadioLabel = jQueryFrame("#page\\:mainForm\\:selectOneRadioLabel");
+  var $selectManyCheckboxLabel = jQueryFrame("#page\\:mainForm\\:selectManyCheckboxLabel");
+  var $selectOneChoiceLabel = jQueryFrame("#page\\:mainForm\\:selectOneChoiceLabel");
+  var $selectOneListboxLabel = jQueryFrame("#page\\:mainForm\\:selectOneListboxLabel");
+  var $selectManyListboxLabel = jQueryFrame("#page\\:mainForm\\:selectManyListboxLabel");
+  var $selectManyShuttleLabel = jQueryFrame("#page\\:mainForm\\:selectManyShuttleLabel");
+  var $starsLabel = jQueryFrame("#page\\:mainForm\\:starsLabel");
+
+  assert.ok($inLabel.hasClass("tobago-required"));
+  assert.ok($dateLabel.hasClass("tobago-required"));
+  assert.ok($fileLabel.hasClass("tobago-required"));
+  assert.ok($textareaLabel.hasClass("tobago-required"));
+  assert.ok($selectBooleanCheckboxLabel.hasClass("tobago-required"));
+  assert.ok($selectBooleanToggleLabel.hasClass("tobago-required"));
+  assert.ok($selectOneRadioLabel.hasClass("tobago-required"));
+  assert.ok($selectManyCheckboxLabel.hasClass("tobago-required"));
+  assert.ok($selectOneChoiceLabel.hasClass("tobago-required"));
+  assert.ok($selectOneListboxLabel.hasClass("tobago-required"));
+  assert.ok($selectManyListboxLabel.hasClass("tobago-required"));
+  assert.ok($selectManyShuttleLabel.hasClass("tobago-required"));
+  assert.ok($starsLabel.hasClass("tobago-required"));
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/21-label-for/label-for.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/21-label-for/label-for.xhtml
new file mode 100644
index 0000000..d820624
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/21-label-for/label-for.xhtml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<ui:composition template="/main.xhtml"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:ui="http://java.sun.com/jsf/facelets">
+  <ui:param name="title" value="Label 'for'-attribute"/>
+  <p>Test if 'required' is set correctly on tc:label.</p>
+
+  <tc:segmentLayout medium="4seg 8seg">
+    <tc:label id="inLabel" for="in" value="In"/>
+    <tc:in id="in" required="true"/>
+
+    <tc:label id="dateLabel" for="date" value="Date"/>
+    <tc:date id="date" required="true"/>
+
+    <tc:label id="fileLabel" for="file" value="File"/>
+    <tc:file id="file" required="true"/>
+
+    <tc:label id="textareaLabel" for="textarea" value="Textarea"/>
+    <tc:textarea id="textarea" required="true"/>
+
+    <tc:label id="selectBooleanCheckboxLabel" for="selectBooleanCheckbox" value="Checkbox"/>
+    <tc:selectBooleanCheckbox id="selectBooleanCheckbox" required="true"/>
+
+    <tc:label id="selectBooleanToggleLabel" for="selectBooleanToggle" value="Toggle"/>
+    <tc:selectBooleanToggle id="selectBooleanToggle" required="true"/>
+
+    <tc:label id="selectOneRadioLabel" for="selectOneRadio" value="Radio Buttons"/>
+    <tc:selectOneRadio id="selectOneRadio" required="true">
+      <tc:selectItem itemLabel="Item One" itemValue="one"/>
+      <tc:selectItem itemLabel="Item Two" itemValue="two"/>
+    </tc:selectOneRadio>
+
+    <tc:label id="selectManyCheckboxLabel" for="selectManyCheckbox" value="Checkboxes"/>
+    <tc:selectManyCheckbox id="selectManyCheckbox" required="true">
+      <tc:selectItem itemLabel="Item One" itemValue="one"/>
+      <tc:selectItem itemLabel="Item Two" itemValue="two"/>
+    </tc:selectManyCheckbox>
+
+    <tc:label id="selectOneChoiceLabel" for="selectOneChoice" value="Dropdown"/>
+    <tc:selectOneChoice id="selectOneChoice" required="true">
+      <tc:selectItem itemLabel="Item One" itemValue="one"/>
+      <tc:selectItem itemLabel="Item Two" itemValue="two"/>
+    </tc:selectOneChoice>
+
+    <tc:label id="selectOneListboxLabel" for="selectOneListbox" value="Listbox (single selection)"/>
+    <tc:selectOneListbox id="selectOneListbox" required="true">
+      <tc:selectItem itemLabel="Item One" itemValue="one"/>
+      <tc:selectItem itemLabel="Item Two" itemValue="two"/>
+    </tc:selectOneListbox>
+
+    <tc:label id="selectManyListboxLabel" for="selectManyListbox" value="Listbox (multiple selection)"/>
+    <tc:selectManyListbox id="selectManyListbox" required="true">
+      <tc:selectItem itemLabel="Item One" itemValue="one"/>
+      <tc:selectItem itemLabel="Item Two" itemValue="two"/>
+    </tc:selectManyListbox>
+
+    <tc:label id="selectManyShuttleLabel" for="selectManyShuttle" value="Shuttle"/>
+    <tc:selectManyShuttle id="selectManyShuttle" required="true">
+      <tc:selectItem itemLabel="Item One" itemValue="one"/>
+      <tc:selectItem itemLabel="Item Two" itemValue="two"/>
+    </tc:selectManyShuttle>
+
+    <tc:label id="starsLabel" for="stars" value="Stars"/>
+    <tc:stars id="stars" required="true"/>
+  </tc:segmentLayout>
+</ui:composition>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/output.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/output.xhtml
new file mode 100644
index 0000000..3400ad7
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/1500-output/output.xhtml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<ui:composition template="/main.xhtml"
+                xmlns:ui="http://java.sun.com/jsf/facelets">
+  <ui:param name="title" value="Output"/>
+  <p>Tests for output fields.</p>
+</ui:composition>