3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js"><div id="cls-Ext.ux.ValidationStatus"></div>/**
9 * @class Ext.ux.ValidationStatus
10 * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
11 * associated form contains validation errors.
12 * @extends Ext.Component
14 * Creates a new ValiationStatus plugin
15 * @param {Object} config A config object
17 Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
18 <div id="cfg-Ext.ux.ValidationStatus-errorIconCls"></div>/**
19 * @cfg {String} errorIconCls
20 * The {@link #iconCls} value to be applied to the status message when there is a
21 * validation error. Defaults to <tt>'x-status-error'</tt>.
23 errorIconCls : 'x-status-error',
24 <div id="cfg-Ext.ux.ValidationStatus-errorListCls"></div>/**
25 * @cfg {String} errorListCls
26 * The css class to be used for the error list when there are validation errors.
27 * Defaults to <tt>'x-status-error-list'</tt>.
29 errorListCls : 'x-status-error-list',
30 <div id="cfg-Ext.ux.ValidationStatus-validIconCls"></div>/**
31 * @cfg {String} validIconCls
32 * The {@link #iconCls} value to be applied to the status message when the form
33 * validates. Defaults to <tt>'x-status-valid'</tt>.
35 validIconCls : 'x-status-valid',
37 <div id="cfg-Ext.ux.ValidationStatus-showText"></div>/**
38 * @cfg {String} showText
39 * The {@link #text} value to be applied when there is a form validation error.
40 * Defaults to <tt>'The form has errors (click for details...)'</tt>.
42 showText : 'The form has errors (click for details...)',
43 <div id="cfg-Ext.ux.ValidationStatus-showText"></div>/**
44 * @cfg {String} showText
45 * The {@link #text} value to display when the error list is displayed.
46 * Defaults to <tt>'Click again to hide the error list'</tt>.
48 hideText : 'Click again to hide the error list',
49 <div id="cfg-Ext.ux.ValidationStatus-submitText"></div>/**
50 * @cfg {String} submitText
51 * The {@link #text} value to be applied when the form is being submitted.
52 * Defaults to <tt>'Saving...'</tt>.
54 submitText : 'Saving...',
58 sb.on('render', function(){
61 this.errors = new Ext.util.MixedCollection();
62 this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
65 this.form = Ext.getCmp(this.form).getForm();
66 this.startMonitoring();
67 this.form.on('beforeaction', function(f, action){
68 if(action.type == 'submit'){
69 // Ignore monitoring while submitting otherwise the field validation
70 // events cause the status message to reset too early
74 var startMonitor = function(){
77 this.form.on('actioncomplete', startMonitor, this);
78 this.form.on('actionfailed', startMonitor, this);
80 }, this, {single:true});
86 // Grab the statusEl after the first layout.
87 sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
98 startMonitoring : function(){
99 this.form.items.each(function(f){
100 f.on('invalid', this.onFieldValidation, this);
101 f.on('valid', this.onFieldValidation, this);
106 stopMonitoring : function(){
107 this.form.items.each(function(f){
108 f.un('invalid', this.onFieldValidation, this);
109 f.un('valid', this.onFieldValidation, this);
114 onDestroy : function(){
115 this.stopMonitoring();
116 this.statusBar.statusEl.un('click', this.onStatusClick, this);
117 Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
121 onFieldValidation : function(f, msg){
126 this.errors.add(f.id, {field:f, msg:msg});
128 this.errors.removeKey(f.id);
130 this.updateErrorList();
131 if(this.errors.getCount() > 0){
132 if(this.statusBar.getText() != this.showText){
133 this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
136 this.statusBar.clearStatus().setIcon(this.validIconCls);
141 updateErrorList : function(){
142 if(this.errors.getCount() > 0){
144 this.errors.each(function(err){
145 msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
147 this.getMsgEl().update(msg+'</ul>');
149 this.getMsgEl().update('');
154 getMsgEl : function(){
156 this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
157 cls: this.errorListCls+' x-hide-offsets'
160 this.msgEl.on('click', function(e){
161 var t = e.getTarget('li', 10, true);
163 Ext.getCmp(t.id.split('x-err-')[1]).focus();
166 }, this, {stopEvent:true}); // prevent anchor click navigation
172 showErrors : function(){
173 this.updateErrorList();
174 this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:0.3, easing:'easeOut'});
175 this.statusBar.setText(this.hideText);
176 this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
180 hideErrors : function(){
181 var el = this.getMsgEl();
183 el.slideOut('b', {duration:0.2, easing:'easeIn'});
184 this.statusBar.setText(this.showText);
186 this.form.getEl().un('click', this.hideErrors, this);
190 onStatusClick : function(){
191 if(this.getMsgEl().isVisible()){
193 }else if(this.errors.getCount() > 0){