From 93c4193f4a3c315c7785bf5f9f522c955ef6fce7 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sat, 5 Aug 2006 00:38:30 +0000 Subject: Fixed #274 --- .gitattributes | 2 ++ HISTORY | 2 ++ framework/Util/TSimpleDateFormatter.php | 5 ++++- framework/Web/Javascripts/js/validator.js | 6 +++++- framework/Web/Javascripts/prado/validation3.js | 12 ++++++++++- framework/Web/UI/WebControls/TBaseValidator.php | 4 ++++ .../Web/UI/WebControls/TDataTypeValidator.php | 3 +++ framework/Web/UI/WebControls/TDatePicker.php | 3 ++- .../tickets/protected/pages/Ticket274.page | 22 ++++++++++++++++++++ .../tickets/tests/Ticket274TestCase.php | 24 ++++++++++++++++++++++ .../validators/tests/DataTypeValidatorTestCase.php | 2 +- 11 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 tests/FunctionalTests/tickets/protected/pages/Ticket274.page create mode 100644 tests/FunctionalTests/tickets/tests/Ticket274TestCase.php diff --git a/.gitattributes b/.gitattributes index 30614810..59691acb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1630,6 +1630,7 @@ tests/FunctionalTests/tickets/protected/pages/Ticket239.page -text tests/FunctionalTests/tickets/protected/pages/Ticket239.php -text tests/FunctionalTests/tickets/protected/pages/Ticket269.page -text tests/FunctionalTests/tickets/protected/pages/Ticket27.page -text +tests/FunctionalTests/tickets/protected/pages/Ticket274.page -text tests/FunctionalTests/tickets/protected/pages/Ticket28.page -text tests/FunctionalTests/tickets/protected/pages/Ticket28.php -text tests/FunctionalTests/tickets/protected/pages/Ticket284.page -text @@ -1656,6 +1657,7 @@ tests/FunctionalTests/tickets/tests/Ticket169TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket191TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket21TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket239TestCase.php -text +tests/FunctionalTests/tickets/tests/Ticket274TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket27TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket284TestCase.php -text tests/FunctionalTests/tickets/tests/Ticket285TestCase.php -text diff --git a/HISTORY b/HISTORY index ae33a67a..460e3e18 100644 --- a/HISTORY +++ b/HISTORY @@ -24,6 +24,8 @@ ENH: Ticket#287 - TControl::broadcastEvent() may raise events now (Qiang) ENH: Ticket#292 - Added THttpRequest::parseUrl() so that it is easier to be extended (Qiang) ENH: Ticket#309 - Added THttpRequest.UrlParamSeparator property (Qiang) ENH: Ticket#316 - Added media type support to CSS files in a theme (Qiang) +ENH: Validating TDatePicker does not need to explictly specific the DateFormat in validators. (Wei) +ENH: TRequireFieldValidator can be used to validate a valid date (Wei). NEW: Added TStyleSheet (Wei) diff --git a/framework/Util/TSimpleDateFormatter.php b/framework/Util/TSimpleDateFormatter.php index 971225b5..03ae7b7d 100644 --- a/framework/Util/TSimpleDateFormatter.php +++ b/framework/Util/TSimpleDateFormatter.php @@ -185,7 +185,10 @@ class TSimpleDateFormatter */ public function isValidDate($value) { - return !is_null($this->parse($value, false)); + if(is_null($value)) + return false; + else + return !is_null($this->parse($value, false)); } /** diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js index ee578ea2..0e39d191 100644 --- a/framework/Web/Javascripts/js/validator.js +++ b/framework/Web/Javascripts/js/validator.js @@ -125,7 +125,11 @@ return value;},getValidationValue:function(control) control=this.control switch(this.options.ControlType) {case'TDatePicker':if(control.type=="text") -return this.trim($F(control));else +{value=this.trim($F(control));if(this.options.DateFormat) +{date=value.toDate(this.options.DateFormat);return date==null?'':date;} +else +return value;} +else {this.observeDatePickerChanges();return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime();} case'THtmlArea':if(typeof tinyMCE!="undefined") tinyMCE.triggerSave();return this.trim($F(control));case'TRadioButton':if(this.options.GroupName) diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js index f5f058c8..b1b20722 100644 --- a/framework/Web/Javascripts/prado/validation3.js +++ b/framework/Web/Javascripts/prado/validation3.js @@ -767,7 +767,17 @@ Prado.WebUI.TBaseValidator.prototype = { case 'TDatePicker': if(control.type == "text") - return this.trim($F(control)); + { + value = this.trim($F(control)); + + if(this.options.DateFormat) + { + date = value.toDate(this.options.DateFormat); + return date == null ? '' : date; + } + else + return value; + } else { this.observeDatePickerChanges(); diff --git a/framework/Web/UI/WebControls/TBaseValidator.php b/framework/Web/UI/WebControls/TBaseValidator.php index b2405996..bcddfa5f 100644 --- a/framework/Web/UI/WebControls/TBaseValidator.php +++ b/framework/Web/UI/WebControls/TBaseValidator.php @@ -165,6 +165,10 @@ abstract class TBaseValidator extends TLabel implements IValidator $options['ControlCssClass'] = $this->getControlCssClass(); $options['ControlType'] = $this->getClientControlClass($control); + + //get date format from date picker target control + if($control instanceof TDatePicker) + $options['DateFormat'] = $control->getDateFormat(); if(!is_null($this->_clientScript)) $options = array_merge($options,$this->_clientScript->getOptions()); diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php index bd7569fc..3e91ec15 100644 --- a/framework/Web/UI/WebControls/TDataTypeValidator.php +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -89,6 +89,9 @@ class TDataTypeValidator extends TBaseValidator */ protected function evaluateDataTypeCheck($value) { + if($value=='') + return true; + switch($this->getDataType()) { case 'Integer': diff --git a/framework/Web/UI/WebControls/TDatePicker.php b/framework/Web/UI/WebControls/TDatePicker.php index 6852f9eb..642d9953 100644 --- a/framework/Web/UI/WebControls/TDatePicker.php +++ b/framework/Web/UI/WebControls/TDatePicker.php @@ -296,7 +296,8 @@ class TDatePicker extends TTextBox { if($this->getText() === '') return ''; - return $this->getTimeStamp(); + $date = $this->getTimeStamp(); + return $date == null ? '' : $date; } /** diff --git a/tests/FunctionalTests/tickets/protected/pages/Ticket274.page b/tests/FunctionalTests/tickets/protected/pages/Ticket274.page new file mode 100644 index 00000000..4e1441ed --- /dev/null +++ b/tests/FunctionalTests/tickets/protected/pages/Ticket274.page @@ -0,0 +1,22 @@ + + + + + + + + + + \ No newline at end of file diff --git a/tests/FunctionalTests/tickets/tests/Ticket274TestCase.php b/tests/FunctionalTests/tickets/tests/Ticket274TestCase.php new file mode 100644 index 00000000..ae976a7f --- /dev/null +++ b/tests/FunctionalTests/tickets/tests/Ticket274TestCase.php @@ -0,0 +1,24 @@ +open('tickets/index.php?page=Ticket274'); + $this->assertTitle('Verifying Ticket 274'); + $this->assertNotVisible($base.'validator1'); + $this->assertNotVisible($base.'validator2'); + + $this->click($base.'button1'); + $this->assertVisible($base.'validator1'); + $this->assertNotVisible($base.'validator2'); + + $this->type($base.'MyDate', 'asd'); + $this->click($base.'button1'); + $this->assertVisible($base.'validator1'); + $this->assertNotVisible($base.'validator2'); + } +} + +?> \ No newline at end of file diff --git a/tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php b/tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php index 1ca3de5d..153be373 100644 --- a/tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php +++ b/tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php @@ -10,7 +10,7 @@ class DataTypeValidatorTestCase extends SeleniumTestCase $base = "ctl0_Content_"; $this->open("validators/index.php?page=DataTypeValidator", ""); $this->verifyTextPresent("Data Type Validator Tests", ""); - $this->clickAndWait("//input[@type='submit' and @value='submit!']", ""); + $this->click("//input[@type='submit' and @value='submit!']", ""); $this->assertNotVisible("{$base}validator1"); $this->assertNotVisible("{$base}validator2"); -- cgit v1.2.3