Web UI for ARGUS server
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.

760 lines
29 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.Field"></div>/**
  16. * @class Ext.form.Field
  17. * @extends Ext.BoxComponent
  18. * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
  19. * @constructor
  20. * Creates a new Field
  21. * @param {Object} config Configuration options
  22. * @xtype field
  23. */
  24. Ext.form.Field = Ext.extend(Ext.BoxComponent, {
  25. <div id="prop-Ext.form.Field-label"></div>/**
  26. * <p>The label Element associated with this Field. <b>Only available after this Field has been rendered by a
  27. * {@link form Ext.layout.FormLayout} layout manager.</b></p>
  28. * @type Ext.Element
  29. * @property label
  30. */
  31. <div id="cfg-Ext.form.Field-inputType"></div>/**
  32. * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password, file (defaults
  33. * to 'text'). The types 'file' and 'password' must be used to render those field types currently -- there are
  34. * no separate Ext components for those. Note that if you use <tt>inputType:'file'</tt>, {@link #emptyText}
  35. * is not supported and should be avoided.
  36. */
  37. <div id="cfg-Ext.form.Field-tabIndex"></div>/**
  38. * @cfg {Number} tabIndex The tabIndex for this field. Note this only applies to fields that are rendered,
  39. * not those which are built via applyTo (defaults to undefined).
  40. */
  41. <div id="cfg-Ext.form.Field-value"></div>/**
  42. * @cfg {Mixed} value A value to initialize this field with (defaults to undefined).
  43. */
  44. <div id="cfg-Ext.form.Field-name"></div>/**
  45. * @cfg {String} name The field's HTML name attribute (defaults to '').
  46. * <b>Note</b>: this property must be set if this field is to be automatically included with
  47. * {@link Ext.form.BasicForm#submit form submit()}.
  48. */
  49. <div id="cfg-Ext.form.Field-cls"></div>/**
  50. * @cfg {String} cls A custom CSS class to apply to the field's underlying element (defaults to '').
  51. */
  52. <div id="cfg-Ext.form.Field-invalidClass"></div>/**
  53. * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to 'x-form-invalid')
  54. */
  55. invalidClass : 'x-form-invalid',
  56. <div id="cfg-Ext.form.Field-invalidText"></div>/**
  57. * @cfg {String} invalidText The error text to use when marking a field invalid and no message is provided
  58. * (defaults to 'The value in this field is invalid')
  59. */
  60. invalidText : 'The value in this field is invalid',
  61. <div id="cfg-Ext.form.Field-focusClass"></div>/**
  62. * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to 'x-form-focus')
  63. */
  64. focusClass : 'x-form-focus',
  65. <div id="cfg-Ext.form.Field-preventMark"></div>/**
  66. * @cfg {Boolean} preventMark
  67. * <tt>true</tt> to disable {@link #markInvalid marking the field invalid}.
  68. * Defaults to <tt>false</tt>.
  69. */
  70. <div id="cfg-Ext.form.Field-validationEvent"></div>/**
  71. * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
  72. automatic validation (defaults to 'keyup').
  73. */
  74. validationEvent : 'keyup',
  75. <div id="cfg-Ext.form.Field-validateOnBlur"></div>/**
  76. * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
  77. */
  78. validateOnBlur : true,
  79. <div id="cfg-Ext.form.Field-validationDelay"></div>/**
  80. * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation
  81. * is initiated (defaults to 250)
  82. */
  83. validationDelay : 250,
  84. <div id="cfg-Ext.form.Field-autoCreate"></div>/**
  85. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  86. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  87. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  88. * <pre><code>{tag: 'input', type: 'text', size: '20', autocomplete: 'off'}</code></pre>
  89. */
  90. defaultAutoCreate : {tag: 'input', type: 'text', size: '20', autocomplete: 'off'},
  91. <div id="cfg-Ext.form.Field-fieldClass"></div>/**
  92. * @cfg {String} fieldClass The default CSS class for the field (defaults to 'x-form-field')
  93. */
  94. fieldClass : 'x-form-field',
  95. <div id="cfg-Ext.form.Field-msgTarget"></div>/**
  96. * @cfg {String} msgTarget <p>The location where the message text set through {@link #markInvalid} should display.
  97. * Must be one of the following values:</p>
  98. * <div class="mdetail-params"><ul>
  99. * <li><code>qtip</code> Display a quick tip containing the message when the user hovers over the field. This is the default.
  100. * <div class="subdesc"><b>{@link Ext.QuickTips#init Ext.QuickTips.init} must have been called for this setting to work.</b></div</li>
  101. * <li><code>title</code> Display the message in a default browser title attribute popup.</li>
  102. * <li><code>under</code> Add a block div beneath the field containing the error message.</li>
  103. * <li><code>side</code> Add an error icon to the right of the field, displaying the message in a popup on hover.</li>
  104. * <li><code>[element id]</code> Add the error message directly to the innerHTML of the specified element.</li>
  105. * </ul></div>
  106. */
  107. msgTarget : 'qtip',
  108. <div id="cfg-Ext.form.Field-msgFx"></div>/**
  109. * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field
  110. * (defaults to 'normal').
  111. */
  112. msgFx : 'normal',
  113. <div id="cfg-Ext.form.Field-readOnly"></div>/**
  114. * @cfg {Boolean} readOnly <tt>true</tt> to mark the field as readOnly in HTML
  115. * (defaults to <tt>false</tt>).
  116. * <br><p><b>Note</b>: this only sets the element's readOnly DOM attribute.
  117. * Setting <code>readOnly=true</code>, for example, will not disable triggering a
  118. * ComboBox or DateField; it gives you the option of forcing the user to choose
  119. * via the trigger without typing in the text box. To hide the trigger use
  120. * <code>{@link Ext.form.TriggerField#hideTrigger hideTrigger}</code>.</p>
  121. */
  122. readOnly : false,
  123. <div id="cfg-Ext.form.Field-disabled"></div>/**
  124. * @cfg {Boolean} disabled True to disable the field (defaults to false).
  125. * <p>Be aware that conformant with the <a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.12.1">HTML specification</a>,
  126. * disabled Fields will not be {@link Ext.form.BasicForm#submit submitted}.</p>
  127. */
  128. disabled : false,
  129. <div id="cfg-Ext.form.Field-submitValue"></div>/**
  130. * @cfg {Boolean} submitValue False to clear the name attribute on the field so that it is not submitted during a form post.
  131. * Defaults to <tt>true</tt>.
  132. */
  133. submitValue: true,
  134. // private
  135. isFormField : true,
  136. // private
  137. msgDisplay: '',
  138. // private
  139. hasFocus : false,
  140. // private
  141. initComponent : function(){
  142. Ext.form.Field.superclass.initComponent.call(this);
  143. this.addEvents(
  144. <div id="event-Ext.form.Field-focus"></div>/**
  145. * @event focus
  146. * Fires when this field receives input focus.
  147. * @param {Ext.form.Field} this
  148. */
  149. 'focus',
  150. <div id="event-Ext.form.Field-blur"></div>/**
  151. * @event blur
  152. * Fires when this field loses input focus.
  153. * @param {Ext.form.Field} this
  154. */
  155. 'blur',
  156. <div id="event-Ext.form.Field-specialkey"></div>/**
  157. * @event specialkey
  158. * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed.
  159. * To handle other keys see {@link Ext.Panel#keys} or {@link Ext.KeyMap}.
  160. * You can check {@link Ext.EventObject#getKey} to determine which key was pressed.
  161. * For example: <pre><code>
  162. var form = new Ext.form.FormPanel({
  163. ...
  164. items: [{
  165. fieldLabel: 'Field 1',
  166. name: 'field1',
  167. allowBlank: false
  168. },{
  169. fieldLabel: 'Field 2',
  170. name: 'field2',
  171. listeners: {
  172. specialkey: function(field, e){
  173. // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
  174. // e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
  175. if (e.{@link Ext.EventObject#getKey getKey()} == e.ENTER) {
  176. var form = field.ownerCt.getForm();
  177. form.submit();
  178. }
  179. }
  180. }
  181. }
  182. ],
  183. ...
  184. });
  185. * </code></pre>
  186. * @param {Ext.form.Field} this
  187. * @param {Ext.EventObject} e The event object
  188. */
  189. 'specialkey',
  190. <div id="event-Ext.form.Field-change"></div>/**
  191. * @event change
  192. * Fires just before the field blurs if the field value has changed.
  193. * @param {Ext.form.Field} this
  194. * @param {Mixed} newValue The new value
  195. * @param {Mixed} oldValue The original value
  196. */
  197. 'change',
  198. <div id="event-Ext.form.Field-invalid"></div>/**
  199. * @event invalid
  200. * Fires after the field has been marked as invalid.
  201. * @param {Ext.form.Field} this
  202. * @param {String} msg The validation message
  203. */
  204. 'invalid',
  205. <div id="event-Ext.form.Field-valid"></div>/**
  206. * @event valid
  207. * Fires after the field has been validated with no errors.
  208. * @param {Ext.form.Field} this
  209. */
  210. 'valid'
  211. );
  212. },
  213. <div id="method-Ext.form.Field-getName"></div>/**
  214. * Returns the {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
  215. * attribute of the field if available.
  216. * @return {String} name The field {@link Ext.form.Field#name name} or {@link Ext.form.ComboBox#hiddenName hiddenName}
  217. */
  218. getName : function(){
  219. return this.rendered && this.el.dom.name ? this.el.dom.name : this.name || this.id || '';
  220. },
  221. // private
  222. onRender : function(ct, position){
  223. if(!this.el){
  224. var cfg = this.getAutoCreate();
  225. if(!cfg.name){
  226. cfg.name = this.name || this.id;
  227. }
  228. if(this.inputType){
  229. cfg.type = this.inputType;
  230. }
  231. this.autoEl = cfg;
  232. }
  233. Ext.form.Field.superclass.onRender.call(this, ct, position);
  234. if(this.submitValue === false){
  235. this.el.dom.removeAttribute('name');
  236. }
  237. var type = this.el.dom.type;
  238. if(type){
  239. if(type == 'password'){
  240. type = 'text';
  241. }
  242. this.el.addClass('x-form-'+type);
  243. }
  244. if(this.readOnly){
  245. this.setReadOnly(true);
  246. }
  247. if(this.tabIndex !== undefined){
  248. this.el.dom.setAttribute('tabIndex', this.tabIndex);
  249. }
  250. this.el.addClass([this.fieldClass, this.cls]);
  251. },
  252. // private
  253. getItemCt : function(){
  254. return this.itemCt;
  255. },
  256. // private
  257. initValue : function(){
  258. if(this.value !== undefined){
  259. this.setValue(this.value);
  260. }else if(!Ext.isEmpty(this.el.dom.value) && this.el.dom.value != this.emptyText){
  261. this.setValue(this.el.dom.value);
  262. }
  263. <div id="prop-Ext.form.Field-originalValue"></div>/**
  264. * The original value of the field as configured in the {@link #value} configuration, or
  265. * as loaded by the last form load operation if the form's {@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  266. * setting is <code>true</code>.
  267. * @type mixed
  268. * @property originalValue
  269. */
  270. this.originalValue = this.getValue();
  271. },
  272. <div id="method-Ext.form.Field-isDirty"></div>/**
  273. * <p>Returns true if the value of this Field has been changed from its original value.
  274. * Will return false if the field is disabled or has not been rendered yet.</p>
  275. * <p>Note that if the owning {@link Ext.form.BasicForm form} was configured with
  276. * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  277. * then the <i>original value</i> is updated when the values are loaded by
  278. * {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#setValues setValues}.</p>
  279. * @return {Boolean} True if this field has been changed from its original value (and
  280. * is not disabled), false otherwise.
  281. */
  282. isDirty : function() {
  283. if(this.disabled || !this.rendered) {
  284. return false;
  285. }
  286. return String(this.getValue()) !== String(this.originalValue);
  287. },
  288. <div id="method-Ext.form.Field-setReadOnly"></div>/**
  289. * Sets the read only state of this field.
  290. * @param {Boolean} readOnly Whether the field should be read only.
  291. */
  292. setReadOnly : function(readOnly){
  293. if(this.rendered){
  294. this.el.dom.readOnly = readOnly;
  295. }
  296. this.readOnly = readOnly;
  297. },
  298. // private
  299. afterRender : function(){
  300. Ext.form.Field.superclass.afterRender.call(this);
  301. this.initEvents();
  302. this.initValue();
  303. },
  304. // private
  305. fireKey : function(e){
  306. if(e.isSpecialKey()){
  307. this.fireEvent('specialkey', this, e);
  308. }
  309. },
  310. <div id="method-Ext.form.Field-reset"></div>/**
  311. * Resets the current field value to the originally loaded value and clears any validation messages.
  312. * See {@link Ext.form.BasicForm}.{@link Ext.form.BasicForm#trackResetOnLoad trackResetOnLoad}
  313. */
  314. reset : function(){
  315. this.setValue(this.originalValue);
  316. this.clearInvalid();
  317. },
  318. // private
  319. initEvents : function(){
  320. this.mon(this.el, Ext.EventManager.getKeyEvent(), this.fireKey, this);
  321. this.mon(this.el, 'focus', this.onFocus, this);
  322. // standardise buffer across all browsers + OS-es for consistent event order.
  323. // (the 10ms buffer for Editors fixes a weird FF/Win editor issue when changing OS window focus)
  324. this.mon(this.el, 'blur', this.onBlur, this, this.inEditor ? {buffer:10} : null);
  325. },
  326. // private
  327. preFocus: Ext.emptyFn,
  328. // private
  329. onFocus : function(){
  330. this.preFocus();
  331. if(this.focusClass){
  332. this.el.addClass(this.focusClass);
  333. }
  334. if(!this.hasFocus){
  335. this.hasFocus = true;
  336. <div id="prop-Ext.form.Field-startValue"></div>/**
  337. * <p>The value that the Field had at the time it was last focused. This is the value that is passed
  338. * to the {@link #change} event which is fired if the value has been changed when the Field is blurred.</p>
  339. * <p><b>This will be undefined until the Field has been visited.</b> Compare {@link #originalValue}.</p>
  340. * @type mixed
  341. * @property startValue
  342. */
  343. this.startValue = this.getValue();
  344. this.fireEvent('focus', this);
  345. }
  346. },
  347. // private
  348. beforeBlur : Ext.emptyFn,
  349. // private
  350. onBlur : function(){
  351. this.beforeBlur();
  352. if(this.focusClass){
  353. this.el.removeClass(this.focusClass);
  354. }
  355. this.hasFocus = false;
  356. if(this.validationEvent !== false && (this.validateOnBlur || this.validationEvent == 'blur')){
  357. this.validate();
  358. }
  359. var v = this.getValue();
  360. if(String(v) !== String(this.startValue)){
  361. this.fireEvent('change', this, v, this.startValue);
  362. }
  363. this.fireEvent('blur', this);
  364. this.postBlur();
  365. },
  366. // private
  367. postBlur : Ext.emptyFn,
  368. <div id="method-Ext.form.Field-isValid"></div>/**
  369. * Returns whether or not the field value is currently valid by
  370. * {@link #validateValue validating} the {@link #processValue processed value}
  371. * of the field. <b>Note</b>: {@link #disabled} fields are ignored.
  372. * @param {Boolean} preventMark True to disable marking the field invalid
  373. * @return {Boolean} True if the value is valid, else false
  374. */
  375. isValid : function(preventMark){
  376. if(this.disabled){
  377. return true;
  378. }
  379. var restore = this.preventMark;
  380. this.preventMark = preventMark === true;
  381. var v = this.validateValue(this.processValue(this.getRawValue()));
  382. this.preventMark = restore;
  383. return v;
  384. },
  385. <div id="method-Ext.form.Field-validate"></div>/**
  386. * Validates the field value
  387. * @return {Boolean} True if the value is valid, else false
  388. */
  389. validate : function(){
  390. if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
  391. this.clearInvalid();
  392. return true;
  393. }
  394. return false;
  395. },
  396. <div id="method-Ext.form.Field-processValue"></div>/**
  397. * This method should only be overridden if necessary to prepare raw values
  398. * for validation (see {@link #validate} and {@link #isValid}). This method
  399. * is expected to return the processed value for the field which will
  400. * be used for validation (see validateValue method).
  401. * @param {Mixed} value
  402. */
  403. processValue : function(value){
  404. return value;
  405. },
  406. <div id="method-Ext.form.Field-validateValue"></div>/**
  407. * Uses getErrors to build an array of validation errors. If any errors are found, markInvalid is called
  408. * with the first and false is returned, otherwise true is returned. Previously, subclasses were invited
  409. * to provide an implementation of this to process validations - from 3.2 onwards getErrors should be
  410. * overridden instead.
  411. * @param {Mixed} The current value of the field
  412. * @return {Boolean} True if all validations passed, false if one or more failed
  413. */
  414. validateValue : function(value) {
  415. //currently, we only show 1 error at a time for a field, so just use the first one
  416. var error = this.getErrors(value)[0];
  417. if (error == undefined) {
  418. return true;
  419. } else {
  420. this.markInvalid(error);
  421. return false;
  422. }
  423. },
  424. <div id="method-Ext.form.Field-getErrors"></div>/**
  425. * Runs this field's validators and returns an array of error messages for any validation failures.
  426. * This is called internally during validation and would not usually need to be used manually.
  427. * Each subclass should override or augment the return value to provide their own errors
  428. * @return {Array} All error messages for this field
  429. */
  430. getErrors: function() {
  431. return [];
  432. },
  433. <div id="method-Ext.form.Field-getActiveError"></div>/**
  434. * Gets the active error message for this field.
  435. * @return {String} Returns the active error message on the field, if there is no error, an empty string is returned.
  436. */
  437. getActiveError : function(){
  438. return this.activeError || '';
  439. },
  440. <div id="method-Ext.form.Field-markInvalid"></div>/**
  441. * <p>Display an error message associated with this field, using {@link #msgTarget} to determine how to
  442. * display the message and applying {@link #invalidClass} to the field's UI element.</p>
  443. * <p><b>Note</b>: this method does not cause the Field's {@link #validate} method to return <code>false</code>
  444. * if the value does <i>pass</i> validation. So simply marking a Field as invalid will not prevent
  445. * submission of forms submitted with the {@link Ext.form.Action.Submit#clientValidation} option set.</p>
  446. * {@link #isValid invalid}.
  447. * @param {String} msg (optional) The validation message (defaults to {@link #invalidText})
  448. */
  449. markInvalid : function(msg){
  450. //don't set the error icon if we're not rendered or marking is prevented
  451. if (this.rendered && !this.preventMark) {
  452. msg = msg || this.invalidText;
  453. var mt = this.getMessageHandler();
  454. if(mt){
  455. mt.mark(this, msg);
  456. }else if(this.msgTarget){
  457. this.el.addClass(this.invalidClass);
  458. var t = Ext.getDom(this.msgTarget);
  459. if(t){
  460. t.innerHTML = msg;
  461. t.style.display = this.msgDisplay;
  462. }
  463. }
  464. }
  465. this.setActiveError(msg);
  466. },
  467. <div id="method-Ext.form.Field-clearInvalid"></div>/**
  468. * Clear any invalid styles/messages for this field
  469. */
  470. clearInvalid : function(){
  471. //don't remove the error icon if we're not rendered or marking is prevented
  472. if (this.rendered && !this.preventMark) {
  473. this.el.removeClass(this.invalidClass);
  474. var mt = this.getMessageHandler();
  475. if(mt){
  476. mt.clear(this);
  477. }else if(this.msgTarget){
  478. this.el.removeClass(this.invalidClass);
  479. var t = Ext.getDom(this.msgTarget);
  480. if(t){
  481. t.innerHTML = '';
  482. t.style.display = 'none';
  483. }
  484. }
  485. }
  486. this.unsetActiveError();
  487. },
  488. <div id="method-Ext.form.Field-setActiveError"></div>/**
  489. * Sets the current activeError to the given string. Fires the 'invalid' event.
  490. * This does not set up the error icon, only sets the message and fires the event. To show the error icon,
  491. * use markInvalid instead, which calls this method internally
  492. * @param {String} msg The error message
  493. * @param {Boolean} suppressEvent True to suppress the 'invalid' event from being fired
  494. */
  495. setActiveError: function(msg, suppressEvent) {
  496. this.activeError = msg;
  497. if (suppressEvent !== true) this.fireEvent('invalid', this, msg);
  498. },
  499. <div id="method-Ext.form.Field-unsetActiveError"></div>/**
  500. * Clears the activeError and fires the 'valid' event. This is called internally by clearInvalid and would not
  501. * usually need to be called manually
  502. * @param {Boolean} suppressEvent True to suppress the 'invalid' event from being fired
  503. */
  504. unsetActiveError: function(suppressEvent) {
  505. delete this.activeError;
  506. if (suppressEvent !== true) this.fireEvent('valid', this);
  507. },
  508. // private
  509. getMessageHandler : function(){
  510. return Ext.form.MessageTargets[this.msgTarget];
  511. },
  512. // private
  513. getErrorCt : function(){
  514. return this.el.findParent('.x-form-element', 5, true) || // use form element wrap if available
  515. this.el.findParent('.x-form-field-wrap', 5, true); // else direct field wrap
  516. },
  517. // Alignment for 'under' target
  518. alignErrorEl : function(){
  519. this.errorEl.setWidth(this.getErrorCt().getWidth(true) - 20);
  520. },
  521. // Alignment for 'side' target
  522. alignErrorIcon : function(){
  523. this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
  524. },
  525. <div id="method-Ext.form.Field-getRawValue"></div>/**
  526. * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
  527. * @return {Mixed} value The field value
  528. */
  529. getRawValue : function(){
  530. var v = this.rendered ? this.el.getValue() : Ext.value(this.value, '');
  531. if(v === this.emptyText){
  532. v = '';
  533. }
  534. return v;
  535. },
  536. <div id="method-Ext.form.Field-getValue"></div>/**
  537. * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
  538. * @return {Mixed} value The field value
  539. */
  540. getValue : function(){
  541. if(!this.rendered) {
  542. return this.value;
  543. }
  544. var v = this.el.getValue();
  545. if(v === this.emptyText || v === undefined){
  546. v = '';
  547. }
  548. return v;
  549. },
  550. <div id="method-Ext.form.Field-setRawValue"></div>/**
  551. * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
  552. * @param {Mixed} value The value to set
  553. * @return {Mixed} value The field value that is set
  554. */
  555. setRawValue : function(v){
  556. return this.rendered ? (this.el.dom.value = (Ext.isEmpty(v) ? '' : v)) : '';
  557. },
  558. <div id="method-Ext.form.Field-setValue"></div>/**
  559. * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
  560. * @param {Mixed} value The value to set
  561. * @return {Ext.form.Field} this
  562. */
  563. setValue : function(v){
  564. this.value = v;
  565. if(this.rendered){
  566. this.el.dom.value = (Ext.isEmpty(v) ? '' : v);
  567. this.validate();
  568. }
  569. return this;
  570. },
  571. // private, does not work for all fields
  572. append : function(v){
  573. this.setValue([this.getValue(), v].join(''));
  574. }
  575. <div id="cfg-Ext.form.Field-autoWidth"></div>/**
  576. * @cfg {Boolean} autoWidth @hide
  577. */
  578. <div id="cfg-Ext.form.Field-autoHeight"></div>/**
  579. * @cfg {Boolean} autoHeight @hide
  580. */
  581. <div id="cfg-Ext.form.Field-autoEl"></div>/**
  582. * @cfg {String} autoEl @hide
  583. */
  584. });
  585. Ext.form.MessageTargets = {
  586. 'qtip' : {
  587. mark: function(field, msg){
  588. field.el.addClass(field.invalidClass);
  589. field.el.dom.qtip = msg;
  590. field.el.dom.qclass = 'x-form-invalid-tip';
  591. if(Ext.QuickTips){ // fix for floating editors interacting with DND
  592. Ext.QuickTips.enable();
  593. }
  594. },
  595. clear: function(field){
  596. field.el.removeClass(field.invalidClass);
  597. field.el.dom.qtip = '';
  598. }
  599. },
  600. 'title' : {
  601. mark: function(field, msg){
  602. field.el.addClass(field.invalidClass);
  603. field.el.dom.title = msg;
  604. },
  605. clear: function(field){
  606. field.el.dom.title = '';
  607. }
  608. },
  609. 'under' : {
  610. mark: function(field, msg){
  611. field.el.addClass(field.invalidClass);
  612. if(!field.errorEl){
  613. var elp = field.getErrorCt();
  614. if(!elp){ // field has no container el
  615. field.el.dom.title = msg;
  616. return;
  617. }
  618. field.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
  619. field.on('resize', field.alignErrorEl, field);
  620. field.on('destroy', function(){
  621. Ext.destroy(this.errorEl);
  622. }, field);
  623. }
  624. field.alignErrorEl();
  625. field.errorEl.update(msg);
  626. Ext.form.Field.msgFx[field.msgFx].show(field.errorEl, field);
  627. },
  628. clear: function(field){
  629. field.el.removeClass(field.invalidClass);
  630. if(field.errorEl){
  631. Ext.form.Field.msgFx[field.msgFx].hide(field.errorEl, field);
  632. }else{
  633. field.el.dom.title = '';
  634. }
  635. }
  636. },
  637. 'side' : {
  638. mark: function(field, msg){
  639. field.el.addClass(field.invalidClass);
  640. if(!field.errorIcon){
  641. var elp = field.getErrorCt();
  642. // field has no container el
  643. if(!elp){
  644. field.el.dom.title = msg;
  645. return;
  646. }
  647. field.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
  648. if (field.ownerCt) {
  649. field.ownerCt.on('afterlayout', field.alignErrorIcon, field);
  650. field.ownerCt.on('expand', field.alignErrorIcon, field);
  651. }
  652. field.on('resize', field.alignErrorIcon, field);
  653. field.on('destroy', function(){
  654. Ext.destroy(this.errorIcon);
  655. }, field);
  656. }
  657. field.alignErrorIcon();
  658. field.errorIcon.dom.qtip = msg;
  659. field.errorIcon.dom.qclass = 'x-form-invalid-tip';
  660. field.errorIcon.show();
  661. },
  662. clear: function(field){
  663. field.el.removeClass(field.invalidClass);
  664. if(field.errorIcon){
  665. field.errorIcon.dom.qtip = '';
  666. field.errorIcon.hide();
  667. }else{
  668. field.el.dom.title = '';
  669. }
  670. }
  671. }
  672. };
  673. // anything other than normal should be considered experimental
  674. Ext.form.Field.msgFx = {
  675. normal : {
  676. show: function(msgEl, f){
  677. msgEl.setDisplayed('block');
  678. },
  679. hide : function(msgEl, f){
  680. msgEl.setDisplayed(false).update('');
  681. }
  682. },
  683. slide : {
  684. show: function(msgEl, f){
  685. msgEl.slideIn('t', {stopFx:true});
  686. },
  687. hide : function(msgEl, f){
  688. msgEl.slideOut('t', {stopFx:true,useDisplay:true});
  689. }
  690. },
  691. slideRight : {
  692. show: function(msgEl, f){
  693. msgEl.fixDisplay();
  694. msgEl.alignTo(f.el, 'tl-tr');
  695. msgEl.slideIn('l', {stopFx:true});
  696. },
  697. hide : function(msgEl, f){
  698. msgEl.slideOut('l', {stopFx:true,useDisplay:true});
  699. }
  700. }
  701. };
  702. Ext.reg('field', Ext.form.Field);
  703. </pre>
  704. </body>
  705. </html>