summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwei <>2006-07-05 04:23:43 +0000
committerwei <>2006-07-05 04:23:43 +0000
commit8d8b6688cbbb1febe92012ccc2a4158fa594fcb3 (patch)
treea9f5d43ea3a6efa4a6590192e4ae7f08655310bb
parent91c4292a8063dd2d7a27e7629c015faa4bf052d6 (diff)
Fixed #223 #225
-rw-r--r--.gitattributes4
-rw-r--r--HISTORY3
-rw-r--r--framework/Web/Javascripts/js/validator.js8
-rw-r--r--framework/Web/Javascripts/prado/validation3.js15
-rw-r--r--framework/Web/UI/WebControls/TRadioButton.php36
-rw-r--r--framework/Web/UI/WebControls/TRequiredFieldValidator.php49
-rw-r--r--tests/FunctionalTests/features/protected/pages/CompositeControl.page12
-rw-r--r--tests/FunctionalTests/features/protected/pages/DatePicker.page61
-rw-r--r--tests/FunctionalTests/features/protected/pages/HtmlArea.page25
-rw-r--r--tests/FunctionalTests/features/tests/CompositeControlTestCase.php23
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/Ticket220.page (renamed from tests/FunctionalTests/features/protected/pages/ClientScripTest.page)0
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/Ticket225.page14
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/Ticket225.php19
-rw-r--r--tests/FunctionalTests/tickets/protected/pages/test.js (renamed from tests/FunctionalTests/features/protected/pages/test.js)0
-rw-r--r--tests/FunctionalTests/tickets/tests/Ticket220TestCase.php18
-rw-r--r--tests/FunctionalTests/tickets/tests/Ticket225TestCase.php24
16 files changed, 173 insertions, 138 deletions
diff --git a/.gitattributes b/.gitattributes
index 6aa5af74..6b2dfe97 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1564,11 +1564,8 @@ tests/FunctionalTests/features/protected/controls/LabeledTextbox.php -text
tests/FunctionalTests/features/protected/controls/Layout.php -text
tests/FunctionalTests/features/protected/controls/Layout.tpl -text
tests/FunctionalTests/features/protected/pages/ColorPicker.page -text
-tests/FunctionalTests/features/protected/pages/CompositeControl.page -text
-tests/FunctionalTests/features/protected/pages/DatePicker.page -text
tests/FunctionalTests/features/protected/pages/FeatureList.page -text
tests/FunctionalTests/features/protected/pages/FeatureList.php -text
-tests/FunctionalTests/features/protected/pages/HtmlArea.page -text
tests/FunctionalTests/features/protected/pages/I18N/BasicI18N.page -text
tests/FunctionalTests/features/protected/pages/I18N/BasicI18N.php -text
tests/FunctionalTests/features/protected/pages/I18N/Home.page -text
@@ -1576,7 +1573,6 @@ tests/FunctionalTests/features/protected/pages/I18N/Home.zh_CN.page -text
tests/FunctionalTests/features/protected/pages/I18N/config.xml -text
tests/FunctionalTests/features/protected/pages/RatingList.page -text
tests/FunctionalTests/features/protected/pages/ValidatorEffects.page -text
-tests/FunctionalTests/features/tests/CompositeControlTestCase.php -text
tests/FunctionalTests/index.php -text
tests/FunctionalTests/quickstart.php -text
tests/FunctionalTests/quickstart/Advanced/I18N.php -text
diff --git a/HISTORY b/HISTORY
index 2ecf7f8a..8a039986 100644
--- a/HISTORY
+++ b/HISTORY
@@ -3,6 +3,9 @@ Version 3.0.3 August 6, 2006
BUG: Ticket#264 - Typos in some exception throw statements (Knut)
BUG: Ticket#268 - THttpResponse.redirect() may fail for some browsers (Qiang)
BUG: TDataGrid may complain getting ItemType on a non-object if the grid is not data-bound (Qiang)
+ENH: Ticket#220 - TClientScripts method to import custom javascript files (Wei)
+ENH: Ticket#225 - TRadioButton::getRadioButtonsInGroup() added (Wei)
+ENH: Ticket#223 - Use TRequiredFieldValidator for TRadioButtons with GroupName property (Wei)
NEW: Added TStyleSheet (Wei)
Version 3.0.2 July 2, 2006
diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js
index f77534a7..959dd193 100644
--- a/framework/Web/Javascripts/js/validator.js
+++ b/framework/Web/Javascripts/js/validator.js
@@ -128,9 +128,13 @@ switch(this.options.ControlType)
return this.trim($F(control));else
{this.observeDatePickerChanges();return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();}
case'THtmlArea':if(typeof tinyMCE!="undefined")
-tinyMCE.triggerSave();return this.trim($F(control));default:if(this.isListControlType())
+tinyMCE.triggerSave();return this.trim($F(control));case'TRadioButton':if(this.options.GroupName)
+return this.getRadioButtonGroupValue();default:if(this.isListControlType())
return this.getFirstSelectedListValue();else
-return this.trim($F(control));}},observeDatePickerChanges:function()
+return this.trim($F(control));}},getRadioButtonGroupValue:function()
+{name=this.control.name;value="";$A(document.getElementsByName(name)).each(function(el)
+{if(el.checked)
+value=el.value;});return value;},observeDatePickerChanges:function()
{if(Prado.Browser().ie)
{var DatePicker=Prado.WebUI.TDatePicker;this.observeChanges(DatePicker.getDayListControl(this.control));this.observeChanges(DatePicker.getMonthListControl(this.control));this.observeChanges(DatePicker.getYearListControl(this.control));}},getSelectedValuesAndChecks:function(elements,initialValue)
{var checked=0;var values=[];var isSelected=this.isCheckBoxType(elements[0])?'checked':'selected';elements.each(function(element)
diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js
index 396b4356..9ee7ed2f 100644
--- a/framework/Web/Javascripts/prado/validation3.js
+++ b/framework/Web/Javascripts/prado/validation3.js
@@ -778,6 +778,9 @@ Prado.WebUI.TBaseValidator.prototype =
if(typeof tinyMCE != "undefined")
tinyMCE.triggerSave();
return this.trim($F(control));
+ case 'TRadioButton':
+ if(this.options.GroupName)
+ return this.getRadioButtonGroupValue();
default:
if(this.isListControlType())
return this.getFirstSelectedListValue();
@@ -786,6 +789,18 @@ Prado.WebUI.TBaseValidator.prototype =
}
},
+ getRadioButtonGroupValue : function()
+ {
+ name = this.control.name;
+ value = "";
+ $A(document.getElementsByName(name)).each(function(el)
+ {
+ if(el.checked)
+ value = el.value;
+ });
+ return value;
+ },
+
/**
* Observe changes in the drop down list date picker, IE only.
*/
diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php
index 9198be1b..6ddd7c96 100644
--- a/framework/Web/UI/WebControls/TRadioButton.php
+++ b/framework/Web/UI/WebControls/TRadioButton.php
@@ -37,6 +37,8 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList');
* between posts to the server.
*
* TRadioButton uses {@link setGroupName GroupName} to group together a set of radio buttons.
+ * Once the {@link setGroupName GroupName} is set, you can use the {@link getRadioButtonsInGroup}
+ * method to get an array of TRadioButtons having the same group name.
*
* If {@link setAutoPostBack AutoPostBack} is set true, changing the radio button state
* will cause postback action. And if {@link setCausesValidation CausesValidation}
@@ -54,6 +56,10 @@ Prado::using('System.Web.UI.WebControls.TRadioButtonList');
class TRadioButton extends TCheckBox
{
/**
+ * @param array list of radio buttons registered.
+ */
+ private static $_radiobuttons=array();
+ /**
* @var string the name used to fetch radiobutton post data
*/
private $_uniqueGroupName=null;
@@ -99,6 +105,36 @@ class TRadioButton extends TCheckBox
public function setGroupName($value)
{
$this->setViewState('GroupName',$value,'');
+ $this->registerRadioButton($this);
+ }
+
+ /**
+ * Register radio button control grouping.
+ * @param TRadioButton control to add
+ */
+ private function registerRadioButton(TRadioButton $control)
+ {
+ $id = $control->getUniqueID();
+ if(!isset(self::$_radiobuttons[$id]))
+ self::$_radiobuttons[$id] = $control;
+ }
+
+ /**
+ * Gets an array of RadioButtons with same group name.
+ * Radio buttons are grouped when the GroupName property is set.
+ * This method will always return at least the current radio button in the array.
+ * @return array list of TRadioButton with the same group
+ */
+ public function getRadioButtonsInGroup()
+ {
+ $group = $this->getUniqueGroupName();
+ $buttons = array();
+ foreach(self::$_radiobuttons as $control)
+ {
+ if($control->getUniqueGroupName() === $group)
+ $buttons[] = $control;
+ }
+ return count($buttons) > 0 ? $buttons : array($this);
}
/**
diff --git a/framework/Web/UI/WebControls/TRequiredFieldValidator.php b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
index b8a939ad..c99d9c19 100644
--- a/framework/Web/UI/WebControls/TRequiredFieldValidator.php
+++ b/framework/Web/UI/WebControls/TRequiredFieldValidator.php
@@ -76,22 +76,47 @@ class TRequiredFieldValidator extends TBaseValidator
protected function evaluateIsValid()
{
$control = $this->getValidationTarget();
- $initial = trim($this->getInitialValue());
if($control instanceof TListControl)
+ return $this->validateListControl($control);
+ else if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0)
+ return $this->validateRadioButtonGroup($control);
+ else
+ return $this->validateStandardControl($control);
+ }
+
+ private function validateListControl($control)
+ {
+ $initial = trim($this->getInitialValue());
+ $count = 0;
+ foreach($control->getItems() as $item)
{
- $count = 0;
- foreach($control->getItems() as $item)
- {
- if($item->getSelected() && $item->getValue() != $initial)
- $count++;
- }
- return $count > 0;
+ if($item->getSelected() && $item->getValue() != $initial)
+ $count++;
}
- else
+ return $count > 0;
+ }
+
+ private function validateRadioButtonGroup($control)
+ {
+ $initial = trim($this->getInitialValue());
+ foreach($control->getRadioButtonsInGroup() as $radio)
{
- $value=$this->getValidationValue($control);
- return trim($value)!==$initial || (is_bool($value) && $value);
+ if($radio->getChecked())
+ {
+ if(strlen($value = $radio->getValue()) > 0)
+ return $value !== $initial;
+ else
+ return true;
+ }
}
+ return false;
+ }
+
+ private function validateStandardControl($control)
+ {
+ $initial = trim($this->getInitialValue());
+ $value=$this->getValidationValue($control);
+ return trim($value)!==$initial || (is_bool($value) && $value);
}
/**
@@ -105,6 +130,8 @@ class TRequiredFieldValidator extends TBaseValidator
$control = $this->getValidationTarget();
if($control instanceof TListControl)
$options['TotalItems'] = $control->getItemCount();
+ if($control instanceof TRadioButton && strlen($control->getGroupName()) > 0)
+ $options['GroupName'] = $control->getGroupName();
return $options;
}
}
diff --git a/tests/FunctionalTests/features/protected/pages/CompositeControl.page b/tests/FunctionalTests/features/protected/pages/CompositeControl.page
deleted file mode 100644
index b135445a..00000000
--- a/tests/FunctionalTests/features/protected/pages/CompositeControl.page
+++ /dev/null
@@ -1,12 +0,0 @@
-<com:TContent ID="Content">
-<h1>Composite Control Test</h1>
- <com:LabeledTextBox id="user" Label.Text="username:" /><br />
- <com:LabeledTextBox id="pass" Label.Text="password:" /><br />
- <com:TButton Text="Submit" />
-
-<com:TPanel Visible=<%= $this->user->TextBox->Text != "" %> >
-<h2>Result</h2>
- User: <%= $this->user->TextBox->Text %> Pass: <%= $this->pass->TextBox->Text %>
-</com:TPanel>
-
-</com:TContent> \ No newline at end of file
diff --git a/tests/FunctionalTests/features/protected/pages/DatePicker.page b/tests/FunctionalTests/features/protected/pages/DatePicker.page
deleted file mode 100644
index 261a6994..00000000
--- a/tests/FunctionalTests/features/protected/pages/DatePicker.page
+++ /dev/null
@@ -1,61 +0,0 @@
-<com:TContent ID="Content">
-
-<h1>TDatePicker Samples</h1>
-
-<table class="sampletable">
-
-<tr>
- <td class="samplenote">Default TDatePicker</td>
- <td class="sampleaction">
- <com:TDatePicker />
- </td>
-</tr>
-
-<tr>
- <td class="samplenote">Button Mode, pre-selected date</td>
- <td class="sampleaction">
- <com:TDatePicker Mode="Button" Date="20-10-2005"/>
- </td>
-</tr>
-
-<tr>
- <td class="samplenote">InputMode="DropDownList", custom DateFormat</td>
- <td class="sampleaction">
- <com:TDatePicker DateFormat="yyyy/MMM" InputMode="DropDownList"/>
- </td>
-</tr>
-
-<tr>
- <td class="samplenote">InputMode="DropDownList", custom DateFormat, Culture</td>
- <td class="sampleaction">
- <com:TDatePicker DateFormat="MMM/yyyy" Culture="fr" InputMode="DropDownList"/>
- </td>
-</tr>
-
-
-<tr>
- <td class="samplenote">Custom DateFormat, culture, ImageButton mode, pre-selected date</td>
- <td class="sampleaction">
- <com:TDatePicker Mode="ImageButton" Culture="zh_CN"
- DateFormat="日期:yyyy年M月d日"
- Timestamp=<%= @strtotime("-1 year") %>/>
- </td>
-</tr>
-
-<tr>
- <td class="samplenote">Custom DateFormat, DropDownList, pre-selected date set in as Text</td>
- <td class="sampleaction">
- <com:TDatePicker DateFormat="yyyy/MMMM/dd" Date="2005/05/15" InputMode="DropDownList"/>
- </td>
-</tr>
-
-<tr>
- <td class="samplenote">DropDownList, pre-selected date as integer</td>
- <td class="sampleaction">
- <com:TDatePicker InputMode="DropDownList" Timestamp=<%= @strtotime("-1 month") %>/>
- </td>
-</tr>
-
-</table>
-
-</com:TContent> \ No newline at end of file
diff --git a/tests/FunctionalTests/features/protected/pages/HtmlArea.page b/tests/FunctionalTests/features/protected/pages/HtmlArea.page
deleted file mode 100644
index 3936e68c..00000000
--- a/tests/FunctionalTests/features/protected/pages/HtmlArea.page
+++ /dev/null
@@ -1,25 +0,0 @@
-
-<com:TContent ID="Content">
-
- <com:THtmlArea ID="text1" />
-
- <com:TRequiredFieldValidator
- ControlToValidate="text1"
- ErrorMessage="*" />
-
- <com:TButton ID="button1" Text="submit 1" />
-
- <com:TButton ID="button2" Text="submit 2" />
-
- <com:THtmlArea ID="text2" />
-
- <com:TRequiredFieldValidator
- ControlToValidate="text2"
- ValidationGroup="group2"
- ErrorMessage="*" />
-
- <com:TButton ID="button3" ValidationGroup="group2" Text="submit 3" />
-
- <com:TButton ID="button4" ValidationGroup="group2" Text="submit 4" />
-
-</com:TContent> \ No newline at end of file
diff --git a/tests/FunctionalTests/features/tests/CompositeControlTestCase.php b/tests/FunctionalTests/features/tests/CompositeControlTestCase.php
deleted file mode 100644
index dda3f63b..00000000
--- a/tests/FunctionalTests/features/tests/CompositeControlTestCase.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/*
- * Created on 28/04/2006
- */
-
-class CompositeControlTestCase extends SeleniumTestCase
-{
-
- function test()
- {
- $base = "ctl0_Content_";
- $this->open("features/index.php?page=CompositeControl", "");
- $this->verifyTextPresent("Composite Control Test", "");
- $this->type("{$base}user_textbox", "Hello");
- $this->type("{$base}pass_textbox", "world");
- $this->clickAndWait("//input[@type='submit' and @value='Submit']", "");
- $this->verifyTextPresent("Result", "");
- $this->verifyTextPresent("User: Hello Pass: world", "");
- }
-
-}
-
-?>
diff --git a/tests/FunctionalTests/features/protected/pages/ClientScripTest.page b/tests/FunctionalTests/tickets/protected/pages/Ticket220.page
index d5b6e182..d5b6e182 100644
--- a/tests/FunctionalTests/features/protected/pages/ClientScripTest.page
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket220.page
diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket225.page b/tests/FunctionalTests/tickets/protected/pages/Ticket225.page
new file mode 100644
index 00000000..362c4dce
--- /dev/null
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket225.page
@@ -0,0 +1,14 @@
+<com:TContent ID="Content">
+ <h1>RadioButton Group Tests</h1>
+ <com:TRadioButton ID="button1" Text="Button 1" GroupName="group1" />
+ <com:TRadioButton ID="button2" Text="Button 2" GroupName="group1" />
+ <com:TRadioButton ID="button3" Text="Button 3" GroupName="group1" />
+
+ <com:TRequiredFieldValidator id="validator1"
+ ControlToValidate="button1"
+ ErrorMessage="*" />
+
+ <com:TLabel ID="label1" Text="Label 1" />
+
+ <com:TButton ID="button4" Text="Show Groupings" OnClick="button4_Clicked" />
+</com:TContent> \ No newline at end of file
diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket225.php b/tests/FunctionalTests/tickets/protected/pages/Ticket225.php
new file mode 100644
index 00000000..2cc3fc38
--- /dev/null
+++ b/tests/FunctionalTests/tickets/protected/pages/Ticket225.php
@@ -0,0 +1,19 @@
+<?php
+
+class Ticket225 extends TPage
+{
+ function button4_Clicked()
+ {
+ $this->label1->setText($this->getGroupIDs($this->button1));
+ }
+
+ private function getGroupIDs($radio)
+ {
+ $ids = '';
+ foreach($radio->getRadioButtonsInGroup() as $control)
+ $ids .= " ".$control->getUniqueID();
+ return $ids;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/FunctionalTests/features/protected/pages/test.js b/tests/FunctionalTests/tickets/protected/pages/test.js
index e8e80b19..e8e80b19 100644
--- a/tests/FunctionalTests/features/protected/pages/test.js
+++ b/tests/FunctionalTests/tickets/protected/pages/test.js
diff --git a/tests/FunctionalTests/tickets/tests/Ticket220TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket220TestCase.php
new file mode 100644
index 00000000..0753f732
--- /dev/null
+++ b/tests/FunctionalTests/tickets/tests/Ticket220TestCase.php
@@ -0,0 +1,18 @@
+<?php
+
+class Ticket220TestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $base="ctl0_Content_";
+ $this->open('tickets/index.php?page=Ticket220');
+ $this->assertTextPresent('ClientScript Test');
+ $this->assertText("{$base}label1", "Label 1");
+
+ $this->click("button1");
+ $this->assertText("{$base}label1", 'Label 1: ["ok", "ok 3?", "ok 2!"]');
+ $this->assertAlertNotPresent();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/FunctionalTests/tickets/tests/Ticket225TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket225TestCase.php
new file mode 100644
index 00000000..966e8383
--- /dev/null
+++ b/tests/FunctionalTests/tickets/tests/Ticket225TestCase.php
@@ -0,0 +1,24 @@
+<?php
+
+class Ticket225TestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $base="ctl0_Content_";
+ $this->open('tickets/index.php?page=Ticket225');
+ $this->assertTextPresent('RadioButton Group Tests');
+ $this->assertText("{$base}label1", "Label 1");
+
+ $this->assertNotVisible("{$base}validator1");
+ $this->click("{$base}button4");
+ $this->assertVisible("{$base}validator1");
+
+ $this->click("{$base}button2");
+ $this->clickAndWait("{$base}button4");
+
+ $this->assertText("{$base}label1", 'ctl0$Content$button1 ctl0$Content$button2 ctl0$Content$button3');
+ $this->assertNotVisible("{$base}validator1");
+ }
+}
+
+?> \ No newline at end of file