Web Interface For Lite Argus Control modules
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.

558 lines
22 KiB

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