From 8b0c8f0d0557d8ab88409cd9691cd1ee279321d5 Mon Sep 17 00:00:00 2001 From: wei <> Date: Tue, 25 Apr 2006 07:01:04 +0000 Subject: Complete #70, update TDateFormat, NumberFormat add zerofill. Update TDatePicker quickstart doc, I18N quickstart doc. --- .gitattributes | 2 + HISTORY | 5 + buildscripts/jsbuilder/build.php | 2 +- buildscripts/texbuilder/build.php | 9 +- .../quickstart/protected/pages/Advanced/I18N.page | 124 ++++++++++++++++++++- .../protected/pages/Controls/DatePicker.page | 75 ++++++++++++- .../pages/Controls/Samples/TDatePicker/Home.page | 61 ++++++++++ .../protected/pages/Controls/Standard.page | 4 +- .../protected/pages/Controls/Validation.page | 28 ++++- framework/I18N/TDateFormat.php | 11 +- framework/I18N/core/DateFormat.php | 12 +- framework/I18N/core/NumberFormat.php | 7 +- framework/I18N/core/NumberFormatInfo.php | 18 +++ framework/Web/Javascripts/js/validator.js | 50 +++++---- framework/Web/Javascripts/prado/validation3.js | 71 ++++++++---- .../Web/UI/WebControls/TDataTypeValidator.php | 13 +++ .../validators/tests/DataTypeValidatorTestCase.php | 49 ++++++++ 17 files changed, 477 insertions(+), 64 deletions(-) create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDatePicker/Home.page create mode 100644 tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php diff --git a/.gitattributes b/.gitattributes index 98a6fe91..7de019bb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -182,6 +182,7 @@ demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.page -text demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php -text demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.page -text demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php -text +demos/quickstart/protected/pages/Controls/Samples/TDatePicker/Home.page -text demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.page -text demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php -text demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.page -text @@ -1014,6 +1015,7 @@ tests/FunctionalTests/validators/tests/ButtonTestCase.php -text tests/FunctionalTests/validators/tests/CheckBoxTestCase.php -text tests/FunctionalTests/validators/tests/CompareValidatorTestCase.php -text tests/FunctionalTests/validators/tests/CustomValidatorTestCase.php -text +tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php -text tests/FunctionalTests/validators/tests/DatePickerTestCase.php -text tests/FunctionalTests/validators/tests/ImageButtonTestCase.php -text tests/FunctionalTests/validators/tests/LinkButtonTestCase.php -text diff --git a/HISTORY b/HISTORY index aff7585b..8ab0c66d 100644 --- a/HISTORY +++ b/HISTORY @@ -5,9 +5,11 @@ BUG: Ticket#135 - TBrowserLogRoute reports wrong timings (Qiang) BUG: Ticket#137 - The JavasciptLogger does not work (Qiang) BUG: Ticket#138 - missing file in TDataGrid (Qiang) BUG: Ticket#139 - TThemeManager::setBasePath() should understand an alias path (Qiang) +BUG: Ticket#70 - Javascript for TDataTypeValidator added (Wei) BUG: Non-control components can now use expressions in their properties (Qiang) BUG: TControl.Visible did not make use of overriden getVisible() (Qiang) BUG: TWizard did not stop navigation upon a validation failure (Qiang) +BUG: NumberFormat will now zero-fill numbers base on the pattern. (Wei) ENH: TButton, TImageButton and TLinkButton now implement IButtonControl interface (Qiang) ENH: TResponse::writeFile takes three additional parameters to allow sending memory data (Qiang) ENH: TButtonColumn can now be a column of image buttons (Qiang) @@ -16,8 +18,11 @@ ENH: Format string in classes extending TListControl can now evaluate an express CHG: Rewrote client-side javascript validators, check your client-side validation behaviour (Wei) CHG: Updated the javascript Prototype library, a few utilties functions REMOVED, may break your existing javascript code. (Wei) CHG: Build javascript without compression, only comments are removed. (Wei) +CHG: TDatePicker's date can be set using Date property, it value must be in same format as DateFormat, TimeStamp must be set as integer (wei) +CHG: TSimpleDateFormatter::parse() now return an integer or null on parse error (Wei) NEW: TListControlValidator (Wei) + Version 3.0RC2 April 16, 2006 ============================= BUG: Ticket#54 - recursive reverse() definition (Wei) diff --git a/buildscripts/jsbuilder/build.php b/buildscripts/jsbuilder/build.php index 910f0394..cc41c963 100644 --- a/buildscripts/jsbuilder/build.php +++ b/buildscripts/jsbuilder/build.php @@ -166,7 +166,7 @@ foreach($libraries as $libFile => $sourceFiles) echo "Saving file {$libFile}\n"; $builds++; } -if(preg_match('/doc*/', $argv[1])) +if(isset($argv[1]) && preg_match('/doc*/', $argv[1])) { $files = ""; foreach($libraries as $lib) diff --git a/buildscripts/texbuilder/build.php b/buildscripts/texbuilder/build.php index 4988bccd..4e2d8be6 100644 --- a/buildscripts/texbuilder/build.php +++ b/buildscripts/texbuilder/build.php @@ -155,7 +155,12 @@ function include_figure($info, $filename) function anchor($matches) { $page = get_current_path(); - return '\hypertarget{'.$page.'/'.$matches[1].'}{}'; + return '\hypertarget{'.$page.'/'.strtolower($matches[1]).'}{}'; +} + +function texttt($matches) +{ + return '\texttt{'.str_replace(array('#','_'),array('\#','\_'), $matches[1]).'}'; } function get_current_path() @@ -222,7 +227,7 @@ function parse_html($page,$html) //text modifiers $html = preg_replace('/([^<]*)<\/b>/', '\textbf{$1}', $html); $html = preg_replace('/([^<]*)<\/i>/', '\emph{$1}', $html); - $html = preg_replace('/([^<]*)<\/tt>/', '\texttt{$1}', $html); + $html = preg_replace_callback('/([^<]*)<\/tt>/', 'texttt', $html); //links $html = preg_replace_callback('/]+href="([^"]*)"[^>]*>([^<]*)<\/a>/', diff --git a/demos/quickstart/protected/pages/Advanced/I18N.page b/demos/quickstart/protected/pages/Advanced/I18N.page index f37e5cf6..4a220c4c 100644 --- a/demos/quickstart/protected/pages/Advanced/I18N.page +++ b/demos/quickstart/protected/pages/Advanced/I18N.page @@ -170,23 +170,145 @@ The time is {time}. <com:TDateFormat Value="12/01/2005" /> -

There are of 4 localized date patterns and 4 localized time patterns. They can be used in any combination. If using a combined pattern, the first must be the date, followed by a space, and lastly the time pattern. For example, full date pattern with short time pattern.

+

The Pattern property accepts 4 predefined localized date patterns and 4 predefined localized time patterns. +

    +
  • fulldate
  • +
  • longdate
  • +
  • mediumdate
  • +
  • shortdate
  • +
  • fulltime
  • +
  • longtime
  • +
  • mediumtime
  • +
  • shorttime
  • +
+The predefined can be used in any combination. If using a combined predefined pattern, +the first pattern must be the date, followed by a space, and lastly the time pattern. +For example, full date pattern with short time pattern. The actual ordering of the +date-time and the actual pattern will be determine automatically from locale data specified +by the Culture property.

<com:TDateFormat Pattern="fulldate shorttime" /> +

You can also specify a custom pattern using the following sub-patterns. +The date/time format is specified by means of a string time pattern. In this pattern, all ASCII letters are reserved as pattern letters, which are defined as the following: + + Symbol Meaning Presentation Example + ------ ------- ------------ ------- + G era designator (Text) AD + y year (Number) 1996 + M month in year (Text & Number) July & 07 + d day in month (Number) 10 + h hour in am/pm (1~12) (Number) 12 + H hour in day (0~23) (Number) 0 + m minute in hour (Number) 30 + s second in minute (Number) 55 + E day of week (Text) Tuesday + D day in year (Number) 189 + F day of week in month (Number) 2 (2nd Wed in July) + w week in year (Number) 27 + W week in month (Number) 2 + a am/pm marker (Text) PM + k hour in day (1~24) (Number) 24 + K hour in am/pm (0~11) (Number) 0 + z time zone (Time) Pacific Standard Time + ' escape for text (Delimiter) 'Date=' + '' single quote (Literal) 'o''clock' + +

+ +

The count of pattern letters determine the format.

+ +

(Text): 4 letters uses full form, less than 4, use short or abbreviated form +if it exists. (e.g., "EEEE" produces "Monday", "EEE" produces "Mon")

+ +

(Number): the minimum number of digits. Shorter numbers are zero-padded + to this amount (e.g. if "m" produces "6", "mm" produces "06"). Year is + handled specially; that is, if the count of 'y' is 2, the Year will be + truncated to 2 digits. (e.g., if "yyyy" produces "1997", "yy" produces "97".) + Unlike other fields, fractional seconds are padded on the right with zero.

+ +

(Text and Number): 3 or over, use text, otherwise use number. (e.g., +"M" produces "1", "MM" produces "01", "MMM" produces "Jan", and "MMMM" +produces "January".)

+ +

Any characters in the pattern that are not in the ranges of ['a'..'z'] +and ['A'..'Z'] will be treated as quoted text. For instance, characters +like ':', '.', ' ', and '@' will appear in the resulting time text +even they are not embraced within single quotes.

+ +

Examples using the US locale: + + +Format Pattern Result +-------------- ------- +"yyyy.MM.dd G 'at' HH:mm:ss" ->> 1996.07.10 AD at 15:08:56 +"EEE, MMM d, ''yy" ->> Wed, Jul 10, '96 +"h:mm a" ->> 12:08 PM +"hh 'o''clock' a, z" ->> 12 o'clock PM, Pacific Daylight Time +"K:mm a" ->> 0:00 PM +"yyyy.MMMM.dd G hh:mm a" ->> 1996.July.10 AD 12:08 PM + +

+

If the Value property is not specified, the current date and time is used.

TNumberFormat

PRADO's Internationalization framework provide localized currency formatting and number formatting. Please note that the TNumberFormat component provides formatting only, it does not perform current conversion or exchange.

+

Numbers can be formatted as currency, percentage, decimal or scientific +numbers by specifying the Type attribute. The valid types are: +

    +
  • currency
  • +
  • percentage
  • +
  • decimal
  • +
  • scientific
  • +
+

+ <com:TNumberFormat Type="currency" Value="100" />

Culture and Currency properties may be specified to format locale specific numbers.

+

If someone from US want to see sales figures from a store in +Germany (say using the EURO currency), formatted using the german + currency, you would need to use the attribute Culture="de_DE" to get +the currency right, e.g. 100,00$. The decimal and grouping separator is +then also from the de_DE locale. This may lead to some confusion because +people from US uses the "," (comma) as thousand separator. Therefore a Currency +attribute is available, so that the output from the following example results in $100.00 + +<com:TNumberFormat Type="currency" + Culture="en_US" Currency="EUR" Value="100" /> + +

+ +

The Pattern property determines the number of digits, thousand grouping +positions, the number of decimal points and the decimal position. The actual characters that +are used to represent the decimal points and thousand points are culture specific +and will change automatically according to the Culture property. The valid +Pattern characters are: +

    +
  • # (hash) - represents the optional digits
  • +
  • 0 (zero) - represents the mandatory digits, zero left filled
  • +
  • . (full stop) - the position of the decimal point (only 1 decimal point is allowed)
  • +
  • , (comma) - thousand point separation (up to 2 commas are allowed)
  • +
+For example, consider the Value="1234567.12345" and +with Culture="en_US" (which uses "," for thousand point separator and "." for decimal separators). + +Pattern Output +------- ------ +##,###.00 ->> 1,234,567.12 +##,###.## ->> 1,234,567.12345 +##,##.0000 ->> 1,23,45,67.1235 +##,###,##.0 ->> 12,345,67.1 +000,000,000.0 ->> 001,234,567.1 + +

TTranslateParameter

Compound messages, i.e., string substitution, can be accomplished with TTranslateParameter. diff --git a/demos/quickstart/protected/pages/Controls/DatePicker.page b/demos/quickstart/protected/pages/Controls/DatePicker.page index 5425f2ab..17d28382 100644 --- a/demos/quickstart/protected/pages/Controls/DatePicker.page +++ b/demos/quickstart/protected/pages/Controls/DatePicker.page @@ -3,8 +3,81 @@

TDatePicker

+

TDatePicker displays a text box for date input purpose. +When the text box receives focus, a calendar will pop up and users can +pick up from it a date that will be automatically entered into the text box. +The format of the date string displayed in the text box is determined by +the DateFormat property. Valid formats are the combination of the +following tokens: + + +Character Format Pattern (en-US) +--------------------------------------------------------------------- + d day digit + dd padded day digit e.g. 01, 02 + M month digit + MM padded month digit + MMM localized abbreviated month names, e.g. Mar, Apr + MMMM localized month name, e.g. March, April + yy 2 digit year + yyyy 4 digit year +--------------------------------------------------------------------- + + +

+The date of the date picker can be set using the Date or Timestamp +properties. The Date property value must be in the same format as the pattern +specified in the DateFormat property. The Timestamp property +only accepts integers such as the Unix timestamp. +

+

-TBD +TDatePicker has three Mode to show the date picker popup. +

    +
  • Basic - Only shows a text input, focusing on the input shows the date picker.
  • +
  • Button - Shows a button next to the text input, clicking on the button shows the date, button text can be by the ButtonText property.
  • +
  • ImageButton - Shows an image next to the text input, clicking on the image shows the date picker, image source can be change through the ImageUrl property.
  • +

+

The CssClass property can be used to override the css class name +for the date picker panel. The CalendarStyle property changes the overall calendar style. +The following CalendarStyle values are available: +

    +
  • default - The default calendar style.
  • +
+

+ +

The InputMode property can be set to "TextBox" or "DropDownList" with +default as "TextBox". In DropDownList mode, in addition to the popup date picker, three +drop down list (day, month and year) are presented to select the date . +When InputMode equals "DropDownList", the order and appearance of the date, month, and year +will depend on the pattern specified in DateFormat property. +

+ +

The popup date picker can be hidden by specifying ShowCalendar as false. Much of the +text of the popup date picker can be changed to a different language using the Culture property. +

+ +

The calendar picker year limit can be set using the FromYear and UpToYear properties +where FromYear is the starting year and UpToYear is the last year selectable. +The starting day of the week can be changed by the FirstDayOfWeek property, with 0 as Sunday, 1 as Monday, etc. +

+ +

Note 1: If the InputMode is "TextBox", the DateFormat should +only NOT contain MMM or MMMM patterns. The +server side date parser will not be able to determine the correct date if MMM or +MMMM are used. When InputMode equals "DropDownList", all patterns can be used.

+ +

Note 2: When the TDatePicker is used together +with a validator, the DateFormat property of the validator must be equal to +the DateFormat of the TDatePicker AND must set DataType="Date" +on the validator to ensure correct validation. See +TCompareValidator, +TDataTypeValidator and +TRangeValidator +for details.

+ + + \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDatePicker/Home.page b/demos/quickstart/protected/pages/Controls/Samples/TDatePicker/Home.page new file mode 100644 index 00000000..e563145d --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TDatePicker/Home.page @@ -0,0 +1,61 @@ + + +

TDatePicker Samples

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Default TDatePicker + +
Button Mode,
pre-selected date 20-10-2005
+ +
InputMode="DropDownList",
custom DateFormat="yyyy/MMM"
+ +
InputMode="DropDownList",
custom DateFormat="MMM/yyyy",
Culture="fr"
+ +
Custom DateFormat="日期:yyyy年M月d日",
culture="zh_CN",
ImageButton mode,
pre-selected using Timestamp=<%= @strtotime("-1 year") %>
+ /> +
Custom DateFormat="yyyy/MMMM/dd",
DropDownList,
pre-selected Date="2005/05/15"
+ +
DropDownList,
pre-selected date Timestamp=<%= @strtotime("-1 month") %>
+ /> +
+ +
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Standard.page b/demos/quickstart/protected/pages/Controls/Standard.page index 9580a0d7..dfaee35b 100644 --- a/demos/quickstart/protected/pages/Controls/Standard.page +++ b/demos/quickstart/protected/pages/Controls/Standard.page @@ -15,7 +15,7 @@ TColorPicker represents an input field taking color values via a color dialog. -
  • * +
  • TDatePicker represents an input field taking date values via a calendar dialog.
  • @@ -27,7 +27,7 @@ TFileUpload represents a file upload field. It allows users to upload a file to server. -
  • +
  • * THead represents the <head> element on an HTML Web page. It is required by a PRADO page should it use themes.
  • diff --git a/demos/quickstart/protected/pages/Controls/Validation.page b/demos/quickstart/protected/pages/Controls/Validation.page index 6fe87fd0..6d83af3d 100644 --- a/demos/quickstart/protected/pages/Controls/Validation.page +++ b/demos/quickstart/protected/pages/Controls/Validation.page @@ -26,14 +26,19 @@ Validators share a common set of properties, which are defined in the base class
  • Dynamic - the space for displaying the error message is NOT reserved. Therefore, showing up the error message will shift the layout of your page around (usually down).
  • +
  • ControlCssClass - the Css class that is applied to the control being validated in case the validation fails.
  • +
  • FocusOnError - set focus at the validating place if the validation fails. Defaults to false.
  • +
  • FocusElementID - the ID of the HTML element that will receive focus if validation fails and FocusOnError is true.
  • +

    TRequiredFieldValidator

    TRequiredFieldValidator ensures that the user enters some data in the specified input field. By default, TRequiredFieldValidator will check if the user input is empty or not. The validation fails if the input is empty. By setting InitialValue, the validator can check if the user input is different from InitialValue. If not, the validation fails.

    +

    TRegularExpressionValidator

    TRegularExpressionValidator verifies the user input against a regular pattern. The validation fails if the input does not match the pattern. The regular expression can be specified by the RegularExpression property. Some commonly used regular expressions include: @@ -58,7 +63,7 @@ Note, TRegularExpressionValidator only checks for nonempty user input. Use a TRe

    -

    TEmailAddressValidator

    +

    TEmailAddressValidator

    TEmailAddressValidator verifies that the user input is a valid email address. The validator uses a regular expression to check if the input is in a valid email address format. If CheckMXRecord is true, the validator will also check whether the MX record indicated by the email address is valid, provided checkdnsrr() is available in the installed PHP.

    @@ -66,7 +71,8 @@ TEmailAddressValidator verifies that the user input is a valid email address. Th Note, if the input being validated is empty, TEmailAddressValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty.

    - + +

    TCompareValidator

    TCompareValidator compares the user input with a constant value specified by ValueToCompare, or another user input specified by ControlToCompare. The Operator property specifies how to compare the values, which includes Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan and LessThanEqual. Before comparison, the values being compared will be converted to the type specified by DataType listed as follows, @@ -75,26 +81,40 @@ TCompareValidator compares the user input with a constant value specified by String - A string data type.

  • Integer - A 32-bit signed integer data type.
  • Float - A double-precision floating point number data type.
  • -
  • Currency - A decimal data type that can contain currency symbols.
  • Date - A date data type. The date format can be specified by setting DateFormat property, which must be recognizable by TSimpleDateFormatter. If the property is not set, the GNU date syntax is assumed.
  • Note, if the input being validated is empty, TEmailAddressValidator will not do validation. Use a TRequiredFieldValidator to ensure the value is not empty.

    +

    +N.B. If validating against a TDatePicker the DataType must be equal to "Date" and the DateFormat property of the validator must be equal to the DateFormat of the TDatePicker. +

    +

    TDataTypeValidator

    TDataTypeValidator verifies if the input data is of specific type indicated by DataType. The data types that can be checked against are the same as those in TCompareValidator.

    +

    +N.B. If validating against a TDatePicker the DataType must be equal to "Date" and the DateFormat property of the validator must be equal to the DateFormat of the TDatePicker. +

    + + +

    TRangeValidator

    TRangeValidator verifies whether an input value is within a specified range. TRangeValidator uses three key properties to perform its validation. The MinValue and MaxValue properties specify the minimum and maximum values of the valid range. The DataType property specifies the data type of the value being validated. The value will be first converted into the specified type and then compare with the valid range. The data types that can be checked against are the same as those in TCompareValidator.

    +

    +N.B. If validating against a TDatePicker the DataType must be equal to "Date" and the DateFormat property of the validator must be equal to the DateFormat of the TDatePicker. +

    + +

    TCustomValidator

    TCustomValidator performs user-defined validation (either server-side or client-side or both) on an input control. @@ -118,7 +138,7 @@ function ValidationFunctionName(sender, parameter) - +

    TValidationSummary

    TValidationSummary displays a summary of validation errors inline on a Web page, in a message box, or both. diff --git a/framework/I18N/TDateFormat.php b/framework/I18N/TDateFormat.php index 8ebbce5e..0f5507ab 100644 --- a/framework/I18N/TDateFormat.php +++ b/framework/I18N/TDateFormat.php @@ -48,10 +48,9 @@ Prado::using('System.I18N.TI18NControl'); * if the Value property is not specified. * - Pattern, string, *
    Gets or sets the formatting pattern. The predefined patterns are - * 'full date', 'long date', 'medium date', 'short date', 'full time', - * 'long time', 'medium time', and 'short time'. Custom patterns can - * specified when the Pattern property does not match the predefined - * patterns. + * 'fulldate', 'longdate', 'mediumdate', 'shortdate', 'fulltime', + * 'longtime', 'mediumtime', and 'shorttime'. Custom patterns can specified + * when the Pattern property does not match the predefined patterns. * * @author Xiang Wei Zhuo * @version v1.0, last update on Sat Dec 11 15:25:11 EST 2004 @@ -69,7 +68,7 @@ class TDateFormat extends TI18NControl * A set of pattern presets and their respective formatting shorthand. * @var array */ - protected $patternPresets = array( + static private $_patternPresets = array( 'fulldate'=>'P','full'=>'P', 'longdate'=>'D','long'=>'d', 'mediumdate'=>'p','medium'=>'p', @@ -132,7 +131,7 @@ class TDateFormat extends TI18NControl protected function getPreset($string) { $string = strtolower($string); - foreach($this->patternPresets as $pattern => $preset) + foreach(self::$_patternPresets as $pattern => $preset) { if($string == $pattern) return $preset; diff --git a/framework/I18N/core/DateFormat.php b/framework/I18N/core/DateFormat.php index 9caca03b..142926f4 100644 --- a/framework/I18N/core/DateFormat.php +++ b/framework/I18N/core/DateFormat.php @@ -128,7 +128,12 @@ class DateFormat if($pattern{0} == "'" && $pattern{strlen($pattern)-1} == "'") { - $tokens[$i] = preg_replace('/(^\')|(\'$)/','',$pattern); + $sub = preg_replace('/(^\')|(\'$)/','',$pattern); + $tokens[$i] = str_replace('``````','\'',$sub); + } + else if($pattern == '``````') + { + $tokens[$i] = '\''; } else { @@ -145,7 +150,7 @@ class DateFormat throw new Exception('function '.$function.' not found.'); } - } + } } return I18N_toEncoding(implode('',$tokens), $charset); @@ -269,6 +274,7 @@ class DateFormat $token = null; $text = false; + $pattern = preg_replace("/''/", '``````', $pattern); for($i = 0; $i < strlen($pattern); $i++) { @@ -278,7 +284,7 @@ class DateFormat } else { - $tokens[] = str_replace("''","'",$token); + $tokens[] = str_replace("","'",$token); $token = $pattern{$i}; } diff --git a/framework/I18N/core/NumberFormat.php b/framework/I18N/core/NumberFormat.php index bde87e65..d1184f86 100644 --- a/framework/I18N/core/NumberFormat.php +++ b/framework/I18N/core/NumberFormat.php @@ -63,7 +63,7 @@ require_once(dirname(__FILE__).'/util.php'); * $ja = new NumberFormat('ja_JP'); * * //Japanese currency pattern, and using Japanese Yen symbol - * $ja->format(123.14,'c','JPY'); //�123 (Yen 123) + * $ja->format(123.14,'c','JPY'); //�?123 (Yen 123) * * For each culture, the symbol for each currency may be different. * @@ -166,12 +166,17 @@ class NumberFormat $string = substr($string, 0, $dp); $integer = ''; + + $digitSize = $this->formatInfo->getDigitSize(); + + $string = str_pad($string, $digitSize, '0',STR_PAD_LEFT); $len = strlen($string); $groupSeparator = $this->formatInfo->GroupSeparator; $groupSize = $this->formatInfo->GroupSizes; + $firstGroup = true; $multiGroup = is_int($groupSize[1]); $count = 0; diff --git a/framework/I18N/core/NumberFormatInfo.php b/framework/I18N/core/NumberFormatInfo.php index 15b9ee5d..3531cc7f 100644 --- a/framework/I18N/core/NumberFormatInfo.php +++ b/framework/I18N/core/NumberFormatInfo.php @@ -324,6 +324,13 @@ class NumberFormatInfo } } } + + if(is_int($decimalPos)) + $digitPattern = substr($pattern,0,$decimalPos); + else + $digitPattern = $pattern; + + $digitPattern = preg_replace('/[^0]/','',$digitPattern); $info['groupPos1'] = $groupPos1; $info['groupSize1'] = $groupSize1; @@ -331,6 +338,7 @@ class NumberFormatInfo $info['groupSize2'] = $groupSize2; $info['decimalPos'] = $decimalPos; $info['decimalPoints'] = $decimalPoints; + $info['digitSize'] = strlen($digitPattern); return $info; } @@ -365,6 +373,16 @@ class NumberFormatInfo return $this->pattern['decimalPoints'] = $value; } + function getDigitSize() + { + return $this->pattern['digitSize']; + } + + function setDigitSize($value) + { + $this->pattern['digitSize'] = $value; + } + /** * Gets the string to use as the decimal separator. * @return string decimal separator. diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js index 38d8a2a4..8659d2e9 100644 --- a/framework/Web/Javascripts/js/validator.js +++ b/framework/Web/Javascripts/js/validator.js @@ -353,7 +353,7 @@ validator.manager.updateSummary(validator.group); this._isObserving[control.id+this.options.ID] = true; } }, -trim : function(value) +_trim : function(value) { return typeof(value) == "string" ? value.trim() : ""; }, @@ -393,20 +393,20 @@ getValidationValue : function(control) { case 'TDatePicker': if(control.type == "text") - return this.trim($F(control)); + return this._trim($F(control)); else { - this.observeDatePickerChanges(); + this._observeDatePickerChanges(); return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime(); } default: - if(this.isListControlType()) - return this.getFirstSelectedListValue(); + if(this._isListControlType()) + return this._getFirstSelectedListValue(); else - return this.trim($F(control)); + return this._trim($F(control)); } }, -observeDatePickerChanges : function() +_observeDatePickerChanges : function() { if(Prado.Browser().ie) { @@ -416,11 +416,11 @@ this.observeChanges(DatePicker.getMonthListControl(this.control)); this.observeChanges(DatePicker.getYearListControl(this.control)); } }, -getSelectedValuesAndChecks : function(elements, initialValue) +_getSelectedValuesAndChecks : function(elements, initialValue) { var checked = 0; var values = []; -var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected'; +var isSelected = this._isCheckBoxType(elements[0]) ? 'checked' : 'selected'; elements.each(function(element) { if(element[isSelected] && element.value != initialValue) @@ -431,7 +431,7 @@ values.push(element.value); }); return {'checks' : checked, 'values' : values}; }, -getListElements : function() +_getListElements : function() { switch(this.options.ControlType) { @@ -440,7 +440,7 @@ var elements = []; for(var i = 0; i < this.options.TotalItems; i++) { var element = $(this.options.ControlToValidate+"_"+i); -if(this.isCheckBoxType(element)) +if(this._isCheckBoxType(element)) elements.push(element); } return elements; @@ -457,7 +457,7 @@ default: return []; } }, -isCheckBoxType : function(element) +_isCheckBoxType : function(element) { if(element && element.type) { @@ -466,18 +466,18 @@ return type == "checkbox" || type == "radio"; } return false; }, -isListControlType : function() +_isListControlType : function() { var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox']; return list.include(this.options.ControlType); }, -getFirstSelectedListValue : function() +_getFirstSelectedListValue : function() { var initial = ""; if(typeof(this.options.InitialValue) != "undefined") initial = this.options.InitialValue; -var elements = this.getListElements(); -var selection = this.getSelectedValuesAndChecks(elements, initial); +var elements = this._getListElements(); +var selection = this._getSelectedValuesAndChecks(elements, initial); return selection.values.length > 0 ? selection.values[0] : initial; } } @@ -493,7 +493,7 @@ return true; else { var a = this.getValidationValue(); -var b = this.trim(this.options.InitialValue); +var b = this._trim(this.options.InitialValue); return(a != b); } } @@ -595,16 +595,16 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator, { evaluateIsValid : function() { -var elements = this.getListElements(); +var elements = this._getListElements(); if(elements && elements.length <= 0) return true; this.observeListElements(elements); -var selection = this.getSelectedValuesAndChecks(elements); +var selection = this._getSelectedValuesAndChecks(elements); return this.isValidList(selection.checks, selection.values); }, observeListElements : function(elements) { -if(Prado.Browser().ie && this.isCheckBoxType(elements[0])) +if(Prado.Browser().ie && this._isCheckBoxType(elements[0])) { var validator = this; elements.each(function(element) @@ -640,3 +640,13 @@ required = this.options.Required.split(/,\s*/); return required; } }); +Prado.WebUI.TDataTypeValidator = Class.extend(Prado.WebUI.TBaseValidator, +{ +evaluateIsValid : function() +{ +var value = this.getValidationValue(); +if(value.length <= 0) +return true; +return this.convert(this.options.DataType, value) != null; +} +}); diff --git a/framework/Web/Javascripts/prado/validation3.js b/framework/Web/Javascripts/prado/validation3.js index 4c189532..40472e7e 100644 --- a/framework/Web/Javascripts/prado/validation3.js +++ b/framework/Web/Javascripts/prado/validation3.js @@ -667,9 +667,9 @@ Prado.WebUI.TBaseValidator.prototype = }, /** - * @return string trims the string value, empty string if value is not string. + * @return string _trims the string value, empty string if value is not string. */ - trim : function(value) + _trim : function(value) { return typeof(value) == "string" ? value.trim() : ""; }, @@ -720,25 +720,26 @@ Prado.WebUI.TBaseValidator.prototype = { case 'TDatePicker': if(control.type == "text") - return this.trim($F(control)); + return this._trim($F(control)); else { - this.observeDatePickerChanges(); + this._observeDatePickerChanges(); return Prado.WebUI.TDatePicker.getDropDownDate(control).getTime(); } default: - if(this.isListControlType()) - return this.getFirstSelectedListValue(); + if(this._isListControlType()) + return this._getFirstSelectedListValue(); else - return this.trim($F(control)); + return this._trim($F(control)); } }, /** * Observe changes in the drop down list date picker, IE only. + * @private */ - observeDatePickerChanges : function() + _observeDatePickerChanges : function() { if(Prado.Browser().ie) { @@ -753,12 +754,13 @@ Prado.WebUI.TBaseValidator.prototype = * Gets numeber selections and their values. * @return object returns selected values in values property * and number of selections in checks property. + * @private */ - getSelectedValuesAndChecks : function(elements, initialValue) + _getSelectedValuesAndChecks : function(elements, initialValue) { var checked = 0; var values = []; - var isSelected = this.isCheckBoxType(elements[0]) ? 'checked' : 'selected'; + var isSelected = this._isCheckBoxType(elements[0]) ? 'checked' : 'selected'; elements.each(function(element) { if(element[isSelected] && element.value != initialValue) @@ -774,8 +776,9 @@ Prado.WebUI.TBaseValidator.prototype = * Gets an array of the list control item input elements, for TCheckBoxList * checkbox inputs are returned, for TListBox HTML option elements are returned. * @return array list control option elements. + * @private */ - getListElements : function() + _getListElements : function() { switch(this.options.ControlType) { @@ -784,7 +787,7 @@ Prado.WebUI.TBaseValidator.prototype = for(var i = 0; i < this.options.TotalItems; i++) { var element = $(this.options.ControlToValidate+"_"+i); - if(this.isCheckBoxType(element)) + if(this._isCheckBoxType(element)) elements.push(element); } return elements; @@ -804,8 +807,9 @@ Prado.WebUI.TBaseValidator.prototype = /** * @return boolean true if element is of checkbox or radio type. + * @private */ - isCheckBoxType : function(element) + _isCheckBoxType : function(element) { if(element && element.type) { @@ -817,8 +821,9 @@ Prado.WebUI.TBaseValidator.prototype = /** * @return boolean true if control to validate is of some of the TListControl type. + * @private */ - isListControlType : function() + _isListControlType : function() { var list = ['TCheckBoxList', 'TRadioButtonList', 'TListBox']; return list.include(this.options.ControlType); @@ -826,14 +831,15 @@ Prado.WebUI.TBaseValidator.prototype = /** * @return string gets the first selected list value, initial value if none found. + * @private */ - getFirstSelectedListValue : function() + _getFirstSelectedListValue : function() { var initial = ""; if(typeof(this.options.InitialValue) != "undefined") initial = this.options.InitialValue; - var elements = this.getListElements(); - var selection = this.getSelectedValuesAndChecks(elements, initial); + var elements = this._getListElements(); + var selection = this._getSelectedValuesAndChecks(elements, initial); return selection.values.length > 0 ? selection.values[0] : initial; } } @@ -862,7 +868,7 @@ Prado.WebUI.TRequiredFieldValidator = Class.extend(Prado.WebUI.TBaseValidator, else { var a = this.getValidationValue(); - var b = this.trim(this.options.InitialValue); + var b = this._trim(this.options.InitialValue); return(a != b); } } @@ -1099,13 +1105,13 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator, */ evaluateIsValid : function() { - var elements = this.getListElements(); + var elements = this._getListElements(); if(elements && elements.length <= 0) return true; this.observeListElements(elements); - var selection = this.getSelectedValuesAndChecks(elements); + var selection = this._getSelectedValuesAndChecks(elements); return this.isValidList(selection.checks, selection.values); }, @@ -1114,7 +1120,7 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator, */ observeListElements : function(elements) { - if(Prado.Browser().ie && this.isCheckBoxType(elements[0])) + if(Prado.Browser().ie && this._isCheckBoxType(elements[0])) { var validator = this; elements.each(function(element) @@ -1165,6 +1171,25 @@ Prado.WebUI.TListControlValidator = Class.extend(Prado.WebUI.TBaseValidator, } }); - - +/** + * TDataTypeValidator verifies if the input data is of the type specified + * by DataType option. + * The following data types are supported: + * - Integer A 32-bit signed integer data type. + * - Float A double-precision floating point number data type. + * - Date A date data type. + * - String A string data type. + * For Date type, the option DateFormat + * will be used to determine how to parse the date string. + */ +Prado.WebUI.TDataTypeValidator = Class.extend(Prado.WebUI.TBaseValidator, +{ + evaluateIsValid : function() + { + var value = this.getValidationValue(); + if(value.length <= 0) + return true; + return this.convert(this.options.DataType, value) != null; + } +}); diff --git a/framework/Web/UI/WebControls/TDataTypeValidator.php b/framework/Web/UI/WebControls/TDataTypeValidator.php index d78be7bf..ebcaace7 100644 --- a/framework/Web/UI/WebControls/TDataTypeValidator.php +++ b/framework/Web/UI/WebControls/TDataTypeValidator.php @@ -98,6 +98,19 @@ class TDataTypeValidator extends TBaseValidator return true; } + /** + * Returns an array of javascript validator options. + * @return array javascript validator options. + */ + protected function getClientScriptOptions() + { + $options = parent::getClientScriptOptions(); + $options['DataType']=$this->getDataType(); + if(($dateFormat=$this->getDateFormat())!=='') + $options['DateFormat']=$dateFormat; + return $options; + } + /** * This method overrides the parent's implementation. * The validation succeeds if the input data is of valid type. diff --git a/tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php b/tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php new file mode 100644 index 00000000..1ca3de5d --- /dev/null +++ b/tests/FunctionalTests/validators/tests/DataTypeValidatorTestCase.php @@ -0,0 +1,49 @@ +open("validators/index.php?page=DataTypeValidator", ""); + $this->verifyTextPresent("Data Type Validator Tests", ""); + $this->clickAndWait("//input[@type='submit' and @value='submit!']", ""); + + $this->assertNotVisible("{$base}validator1"); + $this->assertNotVisible("{$base}validator2"); + $this->assertNotVisible("{$base}validator3"); + + $this->type("{$base}textbox1", "a"); + $this->type("{$base}textbox2", "b"); + $this->type("{$base}textbox3", "c"); + $this->click("//input[@type='submit' and @value='submit!']", ""); + + $this->assertVisible("{$base}validator1"); + $this->assertVisible("{$base}validator2"); + $this->assertVisible("{$base}validator3"); + + $this->type("{$base}textbox1", "12"); + $this->type("{$base}textbox2", "12.5"); + $this->type("{$base}textbox3", "2/10/2005"); + $this->clickAndWait("//input[@type='submit' and @value='submit!']", ""); + + $this->assertNotVisible("{$base}validator1"); + $this->assertNotVisible("{$base}validator2"); + $this->assertNotVisible("{$base}validator3"); + + $this->type("{$base}textbox1", "12.2"); + $this->type("{$base}textbox2", "-12.5"); + $this->type("{$base}textbox3", "2/13/2005"); + $this->click("//input[@type='submit' and @value='submit!']", ""); + + $this->assertVisible("{$base}validator1"); + $this->assertNotVisible("{$base}validator2"); + $this->assertVisible("{$base}validator3"); + } + +} + +?> -- cgit v1.2.3