Repository: tapestry-5
Updated Branches:
  refs/heads/master 1acd9d22e -> 4bd1acdba


TAP5-2231: Improper handling of Radio buttons inside Ajax forms


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/4bd1acdb
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/4bd1acdb
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/4bd1acdb

Branch: refs/heads/master
Commit: 4bd1acdbab1945f41d61ffac355b3e014a25c4eb
Parents: 1acd9d2
Author: Howard M. Lewis Ship <[email protected]>
Authored: Mon Mar 24 15:39:01 2014 -0700
Committer: Howard M. Lewis Ship <[email protected]>
Committed: Mon Mar 24 15:39:01 2014 -0700

----------------------------------------------------------------------
 .../META-INF/modules/t5/core/forms.coffee       |  6 +-
 tapestry-core/src/test/app1/AjaxRadioDemo.tml   | 64 ++++++++++++++++
 .../integration/app1/AjaxGroovyTests.groovy     | 25 +++++++
 .../integration/app1/pages/AjaxRadioDemo.java   | 78 ++++++++++++++++++++
 .../tapestry5/integration/app1/pages/Index.java | 12 +--
 5 files changed, 177 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4bd1acdb/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee 
b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
index c09a716..10c812e 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/t5/core/forms.coffee
@@ -73,10 +73,10 @@ define ["./events", "./dom", "underscore"],
           # is handled by keeping a hidden field active with the data Tapestry 
needs
           # on the server.
           return if type is "file" || type is "submit"
-          
-          return if type is "checkbox" && field.checked() is false
 
-          value = field.value()
+        return if (type is "checkbox" or type is "radio") and field.checked() 
is false
+
+        value = field.value()
 
           return if value is null
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4bd1acdb/tapestry-core/src/test/app1/AjaxRadioDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/AjaxRadioDemo.tml 
b/tapestry-core/src/test/app1/AjaxRadioDemo.tml
new file mode 100644
index 0000000..a7f4150
--- /dev/null
+++ b/tapestry-core/src/test/app1/AjaxRadioDemo.tml
@@ -0,0 +1,64 @@
+<html t:type="Border" 
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
+
+    <h1>Ajax Radio Demo</h1>
+
+    <t:zone>
+
+        <p>Choose a department and position:</p>
+
+        <t:form t:id="data" zone="^">
+            <t:errors/>
+
+            <t:radiogroup t:id="department" t:validate="required">
+                <div class="well">
+
+                    <t:loop source="departments" value="loopValue">
+
+                        <div class="radio">
+                            <label>
+                                <t:radio t:id="radio" value="loopValue"/>
+                                ${label}
+                            </label>
+                        </div>
+
+                    </t:loop>
+                </div>
+
+            </t:radiogroup>
+
+            <t:radiogroup t:id="position">
+                <div class="well">
+                    <div class="radio-inline">
+                        <label>
+                            <t:radio t:id="radio1" value="literal:TEMP"/>
+                            Temp
+                        </label>
+                    </div>
+                    <div class="radio-inline">
+                        <label>
+                            <t:radio t:id="radio2" value="literal:LIFER"/>
+                            Lifer
+                        </label>
+                    </div>
+                </div>
+            </t:radiogroup>
+
+            <input class="btn btn-primary" type="submit" value="Update"/>
+            <t:actionlink class="btn btn-default" 
t:id="reset">reset</t:actionlink>
+        </t:form>
+
+    </t:zone>
+
+    <t:block t:id="dataOutput">
+
+        <dl>
+            <dt>Department</dt>
+            <dd id="selected-department">${department}</dd>
+            <dt>Position</dt>
+            <dd id="selected-position">${position}</dd>
+        </dl>
+
+    </t:block>
+
+
+</html>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4bd1acdb/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy
 
b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy
new file mode 100644
index 0000000..4ea2c24
--- /dev/null
+++ 
b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/AjaxGroovyTests.groovy
@@ -0,0 +1,25 @@
+package org.apache.tapestry5.integration.app1
+
+import org.testng.annotations.Test
+
+
+class AjaxGroovyTests extends App1TestCase {
+
+    /** TAP5-2231 */
+    @Test
+    void radio_buttons_in_ajax_form() {
+
+        openLinks "Ajax Radio Demo"
+
+        click "css=label:contains('It')"
+        click "css=label:contains('Temp')"
+
+        click SUBMIT
+
+        waitForElementToAppear "selected-department"
+
+        assertText "selected-department", "IT"
+        assertText "selected-position", "TEMP"
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4bd1acdb/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AjaxRadioDemo.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AjaxRadioDemo.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AjaxRadioDemo.java
new file mode 100644
index 0000000..3fdb85d
--- /dev/null
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/AjaxRadioDemo.java
@@ -0,0 +1,78 @@
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.Block;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.integration.app1.data.Department;
+import org.apache.tapestry5.internal.TapestryInternalUtils;
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
+public class AjaxRadioDemo
+{
+    private Department department;
+
+    private String position;
+
+    private Department loopValue;
+
+    @Inject
+    private Messages messages;
+
+    @Inject
+    private ComponentResources resources;
+
+    @Inject
+    private Block dataOutput;
+
+    void onActionFromReset()
+    {
+        resources.discardPersistentFieldChanges();
+    }
+
+    public Department[] getDepartments()
+    {
+        return Department.values();
+    }
+
+    public Department getDepartment()
+    {
+        return department;
+    }
+
+    public String getPosition()
+    {
+        return position;
+    }
+
+    public Department getLoopValue()
+    {
+        return loopValue;
+    }
+
+    public void setDepartment(Department department)
+    {
+        this.department = department;
+    }
+
+    public void setPosition(String position)
+    {
+        this.position = position;
+    }
+
+    public void setLoopValue(Department loopValue)
+    {
+        this.loopValue = loopValue;
+    }
+
+    public String getLabel()
+    {
+        return TapestryInternalUtils.getLabelForEnum(messages, loopValue);
+    }
+
+    Object onSuccessFromData()
+    {
+        return dataOutput;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4bd1acdb/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
index 6baf728..86d441a 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
@@ -59,6 +59,8 @@ public class Index
     private static final List<Item> ITEMS = CollectionFactory
             .newList(
 
+                    new Item("AjaxRadioDemo", "Ajax Radio Demo", "Radio 
components inside an Ajax form"),
+
                     new Item("TimeIntervalDemo", "TimeInterval Demo", 
"Interval component, based on Moment.js"),
 
                     new Item("LocalDateDemo", "LocalDate Demo", "LocalDate 
component, based on Moment.js"),
@@ -320,7 +322,7 @@ public class Index
 
                     new Item("GridRemoveReorderDemo", "Grid Remove/Reorder 
Demo",
                             "handling of remove and reorder parameters"),
-                            
+
                     new Item("EmptyGrid", "Empty Grid Demo", "show table for 
empty data sources"),
 
                     new Item("protected", "Protected Page",
@@ -505,10 +507,10 @@ public class Index
 
                     new Item("SelectModelFromObjectsAndPropertyNameDemo", 
"SelectModel from objects and property name",
                             "Creating a SelectModel from a list of objects and 
a label property name"),
-                            
+
                     new Item("SelectModelFromObjectsDemo", "SelectModel from 
objects",
                             "Creating a SelectModel from a list of objects"),
-                            
+
                     new Item("SelectModelCoercionDemo", "SelectModel coercion",
                             "Creating a SelectModel from a list of objects 
using coercion"),
 
@@ -550,9 +552,9 @@ public class Index
 
                     new Item("UnknownActivationContextDemo", "Unknown 
Activation Context Demo", "Page refuse to serve if called with an unknown 
activation context (TAP5-2070)",
                             "Unwanted", "context"),
-                    
+
                     new Item("ModuleConfigurationCallbackDemo", 
"ModuleConfigurationCallback Demo", "Shows an example of changing the 
Require.js configuration using JavaScriptSupport.addModuleConfigurationDemo()"),
-                    
+
                     new Item("PartialTemplateRendererDemo", 
"PartialTemplateRenderer Demo", "Shows some examples of rendering blocks and 
components to a String using PartialTemplateRenderer")
 
             );

Reply via email to