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.

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