source: Dev/trunk/src/client/dijit/form/CurrencyTextBox.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.9 KB
Line 
1define([
2        "dojo/currency", // currency._mixInDefaults currency.format currency.parse currency.regexp
3        "dojo/_base/declare", // declare
4        "dojo/_base/lang", // lang.hitch
5        "./NumberTextBox"
6], function(currency, declare, lang, NumberTextBox){
7
8        // module:
9        //              dijit/form/CurrencyTextBox
10
11        /*=====
12        var __Constraints = declare([NumberTextBox.__Constraints, currency.__FormatOptions, currency.__ParseOptions], {
13                // summary:
14                //              Specifies both the rules on valid/invalid values (minimum, maximum,
15                //              number of required decimal places), and also formatting options for
16                //              displaying the value when the field is not focused (currency symbol,
17                //              etc.)
18                // description:
19                //              Follows the pattern of `dijit/form/NumberTextBox.__Constraints`.
20                //              In general developers won't need to set this parameter
21                // example:
22                //              To ensure that the user types in the cents (for example, 1.00 instead of just 1):
23                //      |               {fractional:true}
24        });
25        =====*/
26
27        return declare("dijit.form.CurrencyTextBox", NumberTextBox, {
28                // summary:
29                //              A validating currency textbox
30                // description:
31                //              CurrencyTextBox is similar to `dijit/form/NumberTextBox` but has a few
32                //              extra features related to currency:
33                //
34                //              1. After specifying the currency type (american dollars, euros, etc.) it automatically
35                //                      sets parse/format options such as how many decimal places to show.
36                //              2. The currency mark (dollar sign, euro mark, etc.) is displayed when the field is blurred
37                //                      but erased during editing, so that the user can just enter a plain number.
38
39                // currency: [const] String
40                //              the [ISO4217](http://en.wikipedia.org/wiki/ISO_4217) currency code, a three letter sequence like "USD"
41                currency: "",
42
43                /*=====
44                // constraints: __Constraints
45                //              Despite the name, this parameter specifies both constraints on the input
46                //              (including minimum/maximum allowed values) as well as
47                //              formatting options.
48                constraints: {},
49                ======*/
50
51                baseClass: "dijitTextBox dijitCurrencyTextBox",
52
53                // Override NumberTextBox._formatter to deal with currencies, ex: converts "123.45" to "$123.45"
54                _formatter: currency.format,
55
56                _parser: currency.parse,
57
58                _regExpGenerator: currency.regexp,
59
60                parse: function(/*String*/ value, /*Object*/ constraints){
61                        // summary:
62                        //              Parses string value as a Currency, according to the constraints object
63                        // tags:
64                        //              protected extension
65                        var v = this.inherited(arguments);
66                        if(isNaN(v) && /\d+/.test(value)){ // currency parse failed, but it could be because they are using NumberTextBox format so try its parse
67                                v = lang.hitch(lang.delegate(this, { _parser: NumberTextBox.prototype._parser }), "inherited")(arguments);
68                        }
69                        return v;
70                },
71
72                _setConstraintsAttr: function(/*Object*/ constraints){
73                        if(!constraints.currency && this.currency){
74                                constraints.currency = this.currency;
75                        }
76                        this.inherited(arguments, [ currency._mixInDefaults(lang.mixin(constraints, { exponent: false })) ]); // get places
77                }
78        });
79});
Note: See TracBrowser for help on using the repository browser.