You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

562 lines
26 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-form-TextField-method-constructor'><span id='Ext-form-TextField'>/**
  19. </span></span> * @class Ext.form.TextField
  20. * @extends Ext.form.Field
  21. * &lt;p&gt;Basic text field. Can be used as a direct replacement for traditional text inputs,
  22. * or as the base class for more sophisticated input controls (like {@link Ext.form.TextArea}
  23. * and {@link Ext.form.ComboBox}).&lt;/p&gt;
  24. * &lt;p&gt;&lt;b&gt;&lt;u&gt;Validation&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
  25. * &lt;p&gt;The validation procedure is described in the documentation for {@link #validateValue}.&lt;/p&gt;
  26. * &lt;p&gt;&lt;b&gt;&lt;u&gt;Alter Validation Behavior&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;
  27. * &lt;p&gt;Validation behavior for each field can be configured:&lt;/p&gt;
  28. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  29. * &lt;li&gt;&lt;code&gt;{@link Ext.form.TextField#invalidText invalidText}&lt;/code&gt; : the default validation message to
  30. * show if any validation step above does not provide a message when invalid&lt;/li&gt;
  31. * &lt;li&gt;&lt;code&gt;{@link Ext.form.TextField#maskRe maskRe}&lt;/code&gt; : filter out keystrokes before any validation occurs&lt;/li&gt;
  32. * &lt;li&gt;&lt;code&gt;{@link Ext.form.TextField#stripCharsRe stripCharsRe}&lt;/code&gt; : filter characters after being typed in,
  33. * but before being validated&lt;/li&gt;
  34. * &lt;li&gt;&lt;code&gt;{@link Ext.form.Field#invalidClass invalidClass}&lt;/code&gt; : alternate style when invalid&lt;/li&gt;
  35. * &lt;li&gt;&lt;code&gt;{@link Ext.form.Field#validateOnBlur validateOnBlur}&lt;/code&gt;,
  36. * &lt;code&gt;{@link Ext.form.Field#validationDelay validationDelay}&lt;/code&gt;, and
  37. * &lt;code&gt;{@link Ext.form.Field#validationEvent validationEvent}&lt;/code&gt; : modify how/when validation is triggered&lt;/li&gt;
  38. * &lt;/ul&gt;&lt;/div&gt;
  39. *
  40. * @constructor Creates a new TextField
  41. * @param {Object} config Configuration options
  42. *
  43. * @xtype textfield
  44. */
  45. Ext.form.TextField = Ext.extend(Ext.form.Field, {
  46. <span id='Ext-form-TextField-cfg-vtypeText'> /**
  47. </span> * @cfg {String} vtypeText A custom error message to display in place of the default message provided
  48. * for the &lt;b&gt;&lt;code&gt;{@link #vtype}&lt;/code&gt;&lt;/b&gt; currently set for this field (defaults to &lt;tt&gt;''&lt;/tt&gt;). &lt;b&gt;Note&lt;/b&gt;:
  49. * only applies if &lt;b&gt;&lt;code&gt;{@link #vtype}&lt;/code&gt;&lt;/b&gt; is set, else ignored.
  50. */
  51. <span id='Ext-form-TextField-cfg-stripCharsRe'> /**
  52. </span> * @cfg {RegExp} stripCharsRe A JavaScript RegExp object used to strip unwanted content from the value
  53. * before validation (defaults to &lt;tt&gt;null&lt;/tt&gt;).
  54. */
  55. <span id='Ext-form-TextField-cfg-grow'> /**
  56. </span> * @cfg {Boolean} grow &lt;tt&gt;true&lt;/tt&gt; if this field should automatically grow and shrink to its content
  57. * (defaults to &lt;tt&gt;false&lt;/tt&gt;)
  58. */
  59. grow : false,
  60. <span id='Ext-form-TextField-cfg-growMin'> /**
  61. </span> * @cfg {Number} growMin The minimum width to allow when &lt;code&gt;&lt;b&gt;{@link #grow}&lt;/b&gt; = true&lt;/code&gt; (defaults
  62. * to &lt;tt&gt;30&lt;/tt&gt;)
  63. */
  64. growMin : 30,
  65. <span id='Ext-form-TextField-cfg-growMax'> /**
  66. </span> * @cfg {Number} growMax The maximum width to allow when &lt;code&gt;&lt;b&gt;{@link #grow}&lt;/b&gt; = true&lt;/code&gt; (defaults
  67. * to &lt;tt&gt;800&lt;/tt&gt;)
  68. */
  69. growMax : 800,
  70. <span id='Ext-form-TextField-cfg-vtype'> /**
  71. </span> * @cfg {String} vtype A validation type name as defined in {@link Ext.form.VTypes} (defaults to &lt;tt&gt;null&lt;/tt&gt;)
  72. */
  73. vtype : null,
  74. <span id='Ext-form-TextField-cfg-maskRe'> /**
  75. </span> * @cfg {RegExp} maskRe An input mask regular expression that will be used to filter keystrokes that do
  76. * not match (defaults to &lt;tt&gt;null&lt;/tt&gt;). The maskRe will not operate on any paste events.
  77. */
  78. maskRe : null,
  79. <span id='Ext-form-TextField-cfg-disableKeyFilter'> /**
  80. </span> * @cfg {Boolean} disableKeyFilter Specify &lt;tt&gt;true&lt;/tt&gt; to disable input keystroke filtering (defaults
  81. * to &lt;tt&gt;false&lt;/tt&gt;)
  82. */
  83. disableKeyFilter : false,
  84. <span id='Ext-form-TextField-cfg-allowBlank'> /**
  85. </span> * @cfg {Boolean} allowBlank Specify &lt;tt&gt;false&lt;/tt&gt; to validate that the value's length is &gt; 0 (defaults to
  86. * &lt;tt&gt;true&lt;/tt&gt;)
  87. */
  88. allowBlank : true,
  89. <span id='Ext-form-TextField-cfg-minLength'> /**
  90. </span> * @cfg {Number} minLength Minimum input field length required (defaults to &lt;tt&gt;0&lt;/tt&gt;)
  91. */
  92. minLength : 0,
  93. <span id='Ext-form-TextField-cfg-maxLength'> /**
  94. </span> * @cfg {Number} maxLength Maximum input field length allowed by validation (defaults to Number.MAX_VALUE).
  95. * This behavior is intended to provide instant feedback to the user by improving usability to allow pasting
  96. * and editing or overtyping and back tracking. To restrict the maximum number of characters that can be
  97. * entered into the field use &lt;tt&gt;&lt;b&gt;{@link Ext.form.Field#autoCreate autoCreate}&lt;/b&gt;&lt;/tt&gt; to add
  98. * any attributes you want to a field, for example:&lt;pre&gt;&lt;code&gt;
  99. var myField = new Ext.form.NumberField({
  100. id: 'mobile',
  101. anchor:'90%',
  102. fieldLabel: 'Mobile',
  103. maxLength: 16, // for validation
  104. autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '10'}
  105. });
  106. &lt;/code&gt;&lt;/pre&gt;
  107. */
  108. maxLength : Number.MAX_VALUE,
  109. <span id='Ext-form-TextField-cfg-minLengthText'> /**
  110. </span> * @cfg {String} minLengthText Error text to display if the &lt;b&gt;&lt;tt&gt;{@link #minLength minimum length}&lt;/tt&gt;&lt;/b&gt;
  111. * validation fails (defaults to &lt;tt&gt;'The minimum length for this field is {minLength}'&lt;/tt&gt;)
  112. */
  113. minLengthText : 'The minimum length for this field is {0}',
  114. <span id='Ext-form-TextField-cfg-maxLengthText'> /**
  115. </span> * @cfg {String} maxLengthText Error text to display if the &lt;b&gt;&lt;tt&gt;{@link #maxLength maximum length}&lt;/tt&gt;&lt;/b&gt;
  116. * validation fails (defaults to &lt;tt&gt;'The maximum length for this field is {maxLength}'&lt;/tt&gt;)
  117. */
  118. maxLengthText : 'The maximum length for this field is {0}',
  119. <span id='Ext-form-TextField-cfg-selectOnFocus'> /**
  120. </span> * @cfg {Boolean} selectOnFocus &lt;tt&gt;true&lt;/tt&gt; to automatically select any existing field text when the field
  121. * receives input focus (defaults to &lt;tt&gt;false&lt;/tt&gt;)
  122. */
  123. selectOnFocus : false,
  124. <span id='Ext-form-TextField-cfg-blankText'> /**
  125. </span> * @cfg {String} blankText The error text to display if the &lt;b&gt;&lt;tt&gt;{@link #allowBlank}&lt;/tt&gt;&lt;/b&gt; validation
  126. * fails (defaults to &lt;tt&gt;'This field is required'&lt;/tt&gt;)
  127. */
  128. blankText : 'This field is required',
  129. <span id='Ext-form-TextField-cfg-validator'> /**
  130. </span> * @cfg {Function} validator
  131. * &lt;p&gt;A custom validation function to be called during field validation ({@link #validateValue})
  132. * (defaults to &lt;tt&gt;null&lt;/tt&gt;). If specified, this function will be called first, allowing the
  133. * developer to override the default validation process.&lt;/p&gt;
  134. * &lt;br&gt;&lt;p&gt;This function will be passed the following Parameters:&lt;/p&gt;
  135. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  136. * &lt;li&gt;&lt;code&gt;value&lt;/code&gt;: &lt;i&gt;Mixed&lt;/i&gt;
  137. * &lt;div class=&quot;sub-desc&quot;&gt;The current field value&lt;/div&gt;&lt;/li&gt;
  138. * &lt;/ul&gt;&lt;/div&gt;
  139. * &lt;br&gt;&lt;p&gt;This function is to Return:&lt;/p&gt;
  140. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  141. * &lt;li&gt;&lt;code&gt;true&lt;/code&gt;: &lt;i&gt;Boolean&lt;/i&gt;
  142. * &lt;div class=&quot;sub-desc&quot;&gt;&lt;code&gt;true&lt;/code&gt; if the value is valid&lt;/div&gt;&lt;/li&gt;
  143. * &lt;li&gt;&lt;code&gt;msg&lt;/code&gt;: &lt;i&gt;String&lt;/i&gt;
  144. * &lt;div class=&quot;sub-desc&quot;&gt;An error message if the value is invalid&lt;/div&gt;&lt;/li&gt;
  145. * &lt;/ul&gt;&lt;/div&gt;
  146. */
  147. validator : null,
  148. <span id='Ext-form-TextField-cfg-regex'> /**
  149. </span> * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation
  150. * (defaults to &lt;tt&gt;null&lt;/tt&gt;). If the test fails, the field will be marked invalid using
  151. * &lt;b&gt;&lt;tt&gt;{@link #regexText}&lt;/tt&gt;&lt;/b&gt;.
  152. */
  153. regex : null,
  154. <span id='Ext-form-TextField-cfg-regexText'> /**
  155. </span> * @cfg {String} regexText The error text to display if &lt;b&gt;&lt;tt&gt;{@link #regex}&lt;/tt&gt;&lt;/b&gt; is used and the
  156. * test fails during validation (defaults to &lt;tt&gt;''&lt;/tt&gt;)
  157. */
  158. regexText : '',
  159. <span id='Ext-form-TextField-cfg-emptyText'> /**
  160. </span> * @cfg {String} emptyText The default text to place into an empty field (defaults to &lt;tt&gt;null&lt;/tt&gt;).
  161. * &lt;b&gt;Note&lt;/b&gt;: that this value will be submitted to the server if this field is enabled and configured
  162. * with a {@link #name}.
  163. */
  164. emptyText : null,
  165. <span id='Ext-form-TextField-cfg-emptyClass'> /**
  166. </span> * @cfg {String} emptyClass The CSS class to apply to an empty field to style the &lt;b&gt;&lt;tt&gt;{@link #emptyText}&lt;/tt&gt;&lt;/b&gt;
  167. * (defaults to &lt;tt&gt;'x-form-empty-field'&lt;/tt&gt;). This class is automatically added and removed as needed
  168. * depending on the current field value.
  169. */
  170. emptyClass : 'x-form-empty-field',
  171. <span id='Ext-form-TextField-cfg-enableKeyEvents'> /**
  172. </span> * @cfg {Boolean} enableKeyEvents &lt;tt&gt;true&lt;/tt&gt; to enable the proxying of key events for the HTML input
  173. * field (defaults to &lt;tt&gt;false&lt;/tt&gt;)
  174. */
  175. initComponent : function(){
  176. Ext.form.TextField.superclass.initComponent.call(this);
  177. this.addEvents(
  178. <span id='Ext-form-TextField-event-autosize'> /**
  179. </span> * @event autosize
  180. * Fires when the &lt;tt&gt;&lt;b&gt;{@link #autoSize}&lt;/b&gt;&lt;/tt&gt; function is triggered. The field may or
  181. * may not have actually changed size according to the default logic, but this event provides
  182. * a hook for the developer to apply additional logic at runtime to resize the field if needed.
  183. * @param {Ext.form.Field} this This text field
  184. * @param {Number} width The new field width
  185. */
  186. 'autosize',
  187. <span id='Ext-form-TextField-event-keydown'> /**
  188. </span> * @event keydown
  189. * Keydown input field event. This event only fires if &lt;tt&gt;&lt;b&gt;{@link #enableKeyEvents}&lt;/b&gt;&lt;/tt&gt;
  190. * is set to true.
  191. * @param {Ext.form.TextField} this This text field
  192. * @param {Ext.EventObject} e
  193. */
  194. 'keydown',
  195. <span id='Ext-form-TextField-event-keyup'> /**
  196. </span> * @event keyup
  197. * Keyup input field event. This event only fires if &lt;tt&gt;&lt;b&gt;{@link #enableKeyEvents}&lt;/b&gt;&lt;/tt&gt;
  198. * is set to true.
  199. * @param {Ext.form.TextField} this This text field
  200. * @param {Ext.EventObject} e
  201. */
  202. 'keyup',
  203. <span id='Ext-form-TextField-event-keypress'> /**
  204. </span> * @event keypress
  205. * Keypress input field event. This event only fires if &lt;tt&gt;&lt;b&gt;{@link #enableKeyEvents}&lt;/b&gt;&lt;/tt&gt;
  206. * is set to true.
  207. * @param {Ext.form.TextField} this This text field
  208. * @param {Ext.EventObject} e
  209. */
  210. 'keypress'
  211. );
  212. },
  213. <span id='Ext-form-TextField-method-initEvents'> // private
  214. </span> initEvents : function(){
  215. Ext.form.TextField.superclass.initEvents.call(this);
  216. if(this.validationEvent == 'keyup'){
  217. this.validationTask = new Ext.util.DelayedTask(this.validate, this);
  218. this.mon(this.el, 'keyup', this.filterValidation, this);
  219. }
  220. else if(this.validationEvent !== false &amp;&amp; this.validationEvent != 'blur'){
  221. this.mon(this.el, this.validationEvent, this.validate, this, {buffer: this.validationDelay});
  222. }
  223. if(this.selectOnFocus || this.emptyText){
  224. this.mon(this.el, 'mousedown', this.onMouseDown, this);
  225. if(this.emptyText){
  226. this.applyEmptyText();
  227. }
  228. }
  229. if(this.maskRe || (this.vtype &amp;&amp; this.disableKeyFilter !== true &amp;&amp; (this.maskRe = Ext.form.VTypes[this.vtype+'Mask']))){
  230. this.mon(this.el, 'keypress', this.filterKeys, this);
  231. }
  232. if(this.grow){
  233. this.mon(this.el, 'keyup', this.onKeyUpBuffered, this, {buffer: 50});
  234. this.mon(this.el, 'click', this.autoSize, this);
  235. }
  236. if(this.enableKeyEvents){
  237. this.mon(this.el, {
  238. scope: this,
  239. keyup: this.onKeyUp,
  240. keydown: this.onKeyDown,
  241. keypress: this.onKeyPress
  242. });
  243. }
  244. },
  245. <span id='Ext-form-TextField-method-onMouseDown'> onMouseDown: function(e){
  246. </span> if(!this.hasFocus){
  247. this.mon(this.el, 'mouseup', Ext.emptyFn, this, { single: true, preventDefault: true });
  248. }
  249. },
  250. <span id='Ext-form-TextField-method-processValue'> processValue : function(value){
  251. </span> if(this.stripCharsRe){
  252. var newValue = value.replace(this.stripCharsRe, '');
  253. if(newValue !== value){
  254. this.setRawValue(newValue);
  255. return newValue;
  256. }
  257. }
  258. return value;
  259. },
  260. <span id='Ext-form-TextField-method-filterValidation'> filterValidation : function(e){
  261. </span> if(!e.isNavKeyPress()){
  262. this.validationTask.delay(this.validationDelay);
  263. }
  264. },
  265. <span id='Ext-form-TextField-method-onDisable'> //private
  266. </span> onDisable: function(){
  267. Ext.form.TextField.superclass.onDisable.call(this);
  268. if(Ext.isIE){
  269. this.el.dom.unselectable = 'on';
  270. }
  271. },
  272. <span id='Ext-form-TextField-method-onEnable'> //private
  273. </span> onEnable: function(){
  274. Ext.form.TextField.superclass.onEnable.call(this);
  275. if(Ext.isIE){
  276. this.el.dom.unselectable = '';
  277. }
  278. },
  279. <span id='Ext-form-TextField-method-onKeyUpBuffered'> // private
  280. </span> onKeyUpBuffered : function(e){
  281. if(this.doAutoSize(e)){
  282. this.autoSize();
  283. }
  284. },
  285. <span id='Ext-form-TextField-method-doAutoSize'> // private
  286. </span> doAutoSize : function(e){
  287. return !e.isNavKeyPress();
  288. },
  289. <span id='Ext-form-TextField-method-onKeyUp'> // private
  290. </span> onKeyUp : function(e){
  291. this.fireEvent('keyup', this, e);
  292. },
  293. <span id='Ext-form-TextField-method-onKeyDown'> // private
  294. </span> onKeyDown : function(e){
  295. this.fireEvent('keydown', this, e);
  296. },
  297. <span id='Ext-form-TextField-method-onKeyPress'> // private
  298. </span> onKeyPress : function(e){
  299. this.fireEvent('keypress', this, e);
  300. },
  301. <span id='Ext-form-TextField-method-reset'> /**
  302. </span> * Resets the current field value to the originally-loaded value and clears any validation messages.
  303. * Also adds &lt;tt&gt;&lt;b&gt;{@link #emptyText}&lt;/b&gt;&lt;/tt&gt; and &lt;tt&gt;&lt;b&gt;{@link #emptyClass}&lt;/b&gt;&lt;/tt&gt; if the
  304. * original value was blank.
  305. */
  306. reset : function(){
  307. Ext.form.TextField.superclass.reset.call(this);
  308. this.applyEmptyText();
  309. },
  310. <span id='Ext-form-TextField-method-applyEmptyText'> applyEmptyText : function(){
  311. </span> if(this.rendered &amp;&amp; this.emptyText &amp;&amp; this.getRawValue().length &lt; 1 &amp;&amp; !this.hasFocus){
  312. this.setRawValue(this.emptyText);
  313. this.el.addClass(this.emptyClass);
  314. }
  315. },
  316. <span id='Ext-form-TextField-method-preFocus'> // private
  317. </span> preFocus : function(){
  318. var el = this.el,
  319. isEmpty;
  320. if(this.emptyText){
  321. if(el.dom.value == this.emptyText){
  322. this.setRawValue('');
  323. isEmpty = true;
  324. }
  325. el.removeClass(this.emptyClass);
  326. }
  327. if(this.selectOnFocus || isEmpty){
  328. el.dom.select();
  329. }
  330. },
  331. <span id='Ext-form-TextField-method-postBlur'> // private
  332. </span> postBlur : function(){
  333. this.applyEmptyText();
  334. },
  335. <span id='Ext-form-TextField-method-filterKeys'> // private
  336. </span> filterKeys : function(e){
  337. if(e.ctrlKey){
  338. return;
  339. }
  340. var k = e.getKey();
  341. if(Ext.isGecko &amp;&amp; (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE &amp;&amp; e.button == -1))){
  342. return;
  343. }
  344. var cc = String.fromCharCode(e.getCharCode());
  345. if(!Ext.isGecko &amp;&amp; e.isSpecialKey() &amp;&amp; !cc){
  346. return;
  347. }
  348. if(!this.maskRe.test(cc)){
  349. e.stopEvent();
  350. }
  351. },
  352. <span id='Ext-form-TextField-method-setValue'> setValue : function(v){
  353. </span> if(this.emptyText &amp;&amp; this.el &amp;&amp; !Ext.isEmpty(v)){
  354. this.el.removeClass(this.emptyClass);
  355. }
  356. Ext.form.TextField.superclass.setValue.apply(this, arguments);
  357. this.applyEmptyText();
  358. this.autoSize();
  359. return this;
  360. },
  361. <span id='Ext-form-TextField-method-getErrors'> /**
  362. </span> * &lt;p&gt;Validates a value according to the field's validation rules and returns an array of errors
  363. * for any failing validations. Validation rules are processed in the following order:&lt;/p&gt;
  364. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  365. *
  366. * &lt;li&gt;&lt;b&gt;1. Field specific validator&lt;/b&gt;
  367. * &lt;div class=&quot;sub-desc&quot;&gt;
  368. * &lt;p&gt;A validator offers a way to customize and reuse a validation specification.
  369. * If a field is configured with a &lt;code&gt;{@link #validator}&lt;/code&gt;
  370. * function, it will be passed the current field value. The &lt;code&gt;{@link #validator}&lt;/code&gt;
  371. * function is expected to return either:
  372. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  373. * &lt;li&gt;Boolean &lt;tt&gt;true&lt;/tt&gt; if the value is valid (validation continues).&lt;/li&gt;
  374. * &lt;li&gt;a String to represent the invalid message if invalid (validation halts).&lt;/li&gt;
  375. * &lt;/ul&gt;&lt;/div&gt;
  376. * &lt;/div&gt;&lt;/li&gt;
  377. *
  378. * &lt;li&gt;&lt;b&gt;2. Basic Validation&lt;/b&gt;
  379. * &lt;div class=&quot;sub-desc&quot;&gt;
  380. * &lt;p&gt;If the &lt;code&gt;{@link #validator}&lt;/code&gt; has not halted validation,
  381. * basic validation proceeds as follows:&lt;/p&gt;
  382. *
  383. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  384. *
  385. * &lt;li&gt;&lt;code&gt;{@link #allowBlank}&lt;/code&gt; : (Invalid message =
  386. * &lt;code&gt;{@link #emptyText}&lt;/code&gt;)&lt;div class=&quot;sub-desc&quot;&gt;
  387. * Depending on the configuration of &lt;code&gt;{@link #allowBlank}&lt;/code&gt;, a
  388. * blank field will cause validation to halt at this step and return
  389. * Boolean true or false accordingly.
  390. * &lt;/div&gt;&lt;/li&gt;
  391. *
  392. * &lt;li&gt;&lt;code&gt;{@link #minLength}&lt;/code&gt; : (Invalid message =
  393. * &lt;code&gt;{@link #minLengthText}&lt;/code&gt;)&lt;div class=&quot;sub-desc&quot;&gt;
  394. * If the passed value does not satisfy the &lt;code&gt;{@link #minLength}&lt;/code&gt;
  395. * specified, validation halts.
  396. * &lt;/div&gt;&lt;/li&gt;
  397. *
  398. * &lt;li&gt;&lt;code&gt;{@link #maxLength}&lt;/code&gt; : (Invalid message =
  399. * &lt;code&gt;{@link #maxLengthText}&lt;/code&gt;)&lt;div class=&quot;sub-desc&quot;&gt;
  400. * If the passed value does not satisfy the &lt;code&gt;{@link #maxLength}&lt;/code&gt;
  401. * specified, validation halts.
  402. * &lt;/div&gt;&lt;/li&gt;
  403. *
  404. * &lt;/ul&gt;&lt;/div&gt;
  405. * &lt;/div&gt;&lt;/li&gt;
  406. *
  407. * &lt;li&gt;&lt;b&gt;3. Preconfigured Validation Types (VTypes)&lt;/b&gt;
  408. * &lt;div class=&quot;sub-desc&quot;&gt;
  409. * &lt;p&gt;If none of the prior validation steps halts validation, a field
  410. * configured with a &lt;code&gt;{@link #vtype}&lt;/code&gt; will utilize the
  411. * corresponding {@link Ext.form.VTypes VTypes} validation function.
  412. * If invalid, either the field's &lt;code&gt;{@link #vtypeText}&lt;/code&gt; or
  413. * the VTypes vtype Text property will be used for the invalid message.
  414. * Keystrokes on the field will be filtered according to the VTypes
  415. * vtype Mask property.&lt;/p&gt;
  416. * &lt;/div&gt;&lt;/li&gt;
  417. *
  418. * &lt;li&gt;&lt;b&gt;4. Field specific regex test&lt;/b&gt;
  419. * &lt;div class=&quot;sub-desc&quot;&gt;
  420. * &lt;p&gt;If none of the prior validation steps halts validation, a field's
  421. * configured &lt;code&gt;{@link #regex}&lt;/code&gt; test will be processed.
  422. * The invalid message for this test is configured with
  423. * &lt;code&gt;{@link #regexText}&lt;/code&gt;.&lt;/p&gt;
  424. * &lt;/div&gt;&lt;/li&gt;
  425. *
  426. * @param {Mixed} value The value to validate. The processed raw value will be used if nothing is passed
  427. * @return {Array} Array of any validation errors
  428. */
  429. getErrors: function(value) {
  430. var errors = Ext.form.TextField.superclass.getErrors.apply(this, arguments);
  431. value = Ext.isDefined(value) ? value : this.processValue(this.getRawValue());
  432. if (Ext.isFunction(this.validator)) {
  433. var msg = this.validator(value);
  434. if (msg !== true) {
  435. errors.push(msg);
  436. }
  437. }
  438. if (value.length &lt; 1 || value === this.emptyText) {
  439. if (this.allowBlank) {
  440. //if value is blank and allowBlank is true, there cannot be any additional errors
  441. return errors;
  442. } else {
  443. errors.push(this.blankText);
  444. }
  445. }
  446. if (!this.allowBlank &amp;&amp; (value.length &lt; 1 || value === this.emptyText)) { // if it's blank
  447. errors.push(this.blankText);
  448. }
  449. if (value.length &lt; this.minLength) {
  450. errors.push(String.format(this.minLengthText, this.minLength));
  451. }
  452. if (value.length &gt; this.maxLength) {
  453. errors.push(String.format(this.maxLengthText, this.maxLength));
  454. }
  455. if (this.vtype) {
  456. var vt = Ext.form.VTypes;
  457. if(!vt[this.vtype](value, this)){
  458. errors.push(this.vtypeText || vt[this.vtype +'Text']);
  459. }
  460. }
  461. if (this.regex &amp;&amp; !this.regex.test(value)) {
  462. errors.push(this.regexText);
  463. }
  464. return errors;
  465. },
  466. <span id='Ext-form-TextField-method-selectText'> /**
  467. </span> * Selects text in this field
  468. * @param {Number} start (optional) The index where the selection should start (defaults to 0)
  469. * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
  470. */
  471. selectText : function(start, end){
  472. var v = this.getRawValue();
  473. var doFocus = false;
  474. if(v.length &gt; 0){
  475. start = start === undefined ? 0 : start;
  476. end = end === undefined ? v.length : end;
  477. var d = this.el.dom;
  478. if(d.setSelectionRange){
  479. d.setSelectionRange(start, end);
  480. }else if(d.createTextRange){
  481. var range = d.createTextRange();
  482. range.moveStart('character', start);
  483. range.moveEnd('character', end-v.length);
  484. range.select();
  485. }
  486. doFocus = Ext.isGecko || Ext.isOpera;
  487. }else{
  488. doFocus = true;
  489. }
  490. if(doFocus){
  491. this.focus();
  492. }
  493. },
  494. <span id='Ext-form-TextField-method-autoSize'> /**
  495. </span> * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
  496. * This only takes effect if &lt;tt&gt;&lt;b&gt;{@link #grow}&lt;/b&gt; = true&lt;/tt&gt;, and fires the {@link #autosize} event.
  497. */
  498. autoSize : function(){
  499. if(!this.grow || !this.rendered){
  500. return;
  501. }
  502. if(!this.metrics){
  503. this.metrics = Ext.util.TextMetrics.createInstance(this.el);
  504. }
  505. var el = this.el;
  506. var v = el.dom.value;
  507. var d = document.createElement('div');
  508. d.appendChild(document.createTextNode(v));
  509. v = d.innerHTML;
  510. Ext.removeNode(d);
  511. d = null;
  512. v += '&amp;#160;';
  513. var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
  514. this.el.setWidth(w);
  515. this.fireEvent('autosize', this, w);
  516. },
  517. <span id='Ext-form-TextField-method-onDestroy'> onDestroy: function(){
  518. </span> if(this.validationTask){
  519. this.validationTask.cancel();
  520. this.validationTask = null;
  521. }
  522. Ext.form.TextField.superclass.onDestroy.call(this);
  523. }
  524. });
  525. Ext.reg('textfield', Ext.form.TextField);
  526. </pre>
  527. </body>
  528. </html>