2 * @class Ext.ux.statusbar.ValidationStatus
3 * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
4 * associated form contains validation errors.
5 * @extends Ext.Component
7 * Creates a new ValiationStatus plugin
8 * @param {Object} config A config object
10 Ext.define('Ext.ux.statusbar.ValidationStatus', {
11 extend: 'Ext.Component',
12 requires: ['Ext.util.MixedCollection'],
14 * @cfg {String} errorIconCls
15 * The {@link #iconCls} value to be applied to the status message when there is a
16 * validation error. Defaults to <tt>'x-status-error'</tt>.
18 errorIconCls : 'x-status-error',
20 * @cfg {String} errorListCls
21 * The css class to be used for the error list when there are validation errors.
22 * Defaults to <tt>'x-status-error-list'</tt>.
24 errorListCls : 'x-status-error-list',
26 * @cfg {String} validIconCls
27 * The {@link #iconCls} value to be applied to the status message when the form
28 * validates. Defaults to <tt>'x-status-valid'</tt>.
30 validIconCls : 'x-status-valid',
33 * @cfg {String} showText
34 * The {@link #text} value to be applied when there is a form validation error.
35 * Defaults to <tt>'The form has errors (click for details...)'</tt>.
37 showText : 'The form has errors (click for details...)',
39 * @cfg {String} showText
40 * The {@link #text} value to display when the error list is displayed.
41 * Defaults to <tt>'Click again to hide the error list'</tt>.
43 hideText : 'Click again to hide the error list',
45 * @cfg {String} submitText
46 * The {@link #text} value to be applied when the form is being submitted.
47 * Defaults to <tt>'Saving...'</tt>.
49 submitText : 'Saving...',
53 sb.on('render', function(){
56 this.errors = Ext.create('Ext.util.MixedCollection');
57 this.listAlign = (sb.statusAlign === 'right' ? 'br-tr?' : 'bl-tl?');
60 this.formPanel = Ext.getCmp(this.form);
61 this.basicForm = this.formPanel.getForm();
62 this.startMonitoring();
63 this.basicForm.on('beforeaction', function(f, action){
64 if(action.type === 'submit'){
65 // Ignore monitoring while submitting otherwise the field validation
66 // events cause the status message to reset too early
70 var startMonitor = function(){
73 this.basicForm.on('actioncomplete', startMonitor, this);
74 this.basicForm.on('actionfailed', startMonitor, this);
76 }, this, {single:true});
82 // Grab the statusEl after the first layout.
83 sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
94 startMonitoring : function() {
95 this.basicForm.getFields().each(function(f){
96 f.on('validitychange', this.onFieldValidation, this);
101 stopMonitoring : function(){
102 this.basicForm.getFields().each(function(f){
103 f.un('validitychange', this.onFieldValidation, this);
108 onDestroy : function(){
109 this.stopMonitoring();
110 this.statusBar.statusEl.un('click', this.onStatusClick, this);
111 this.callParent(arguments);
115 onFieldValidation : function(f, isValid){
119 var msg = f.getErrors()[0];
121 this.errors.add(f.id, {field:f, msg:msg});
123 this.errors.removeAtKey(f.id);
125 this.updateErrorList();
126 if(this.errors.getCount() > 0) {
127 if(this.statusBar.getText() !== this.showText){
128 this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
131 this.statusBar.clearStatus().setIcon(this.validIconCls);
136 updateErrorList : function(){
137 if(this.errors.getCount() > 0){
139 this.errors.each(function(err){
140 msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
142 this.getMsgEl().update(msg+'</ul>');
144 this.getMsgEl().update('');
147 this.getMsgEl().setSize('auto', 'auto');
151 getMsgEl : function(){
153 this.msgEl = Ext.core.DomHelper.append(Ext.getBody(), {
154 cls: this.errorListCls
157 this.msgEl.on('click', function(e){
158 var t = e.getTarget('li', 10, true);
160 Ext.getCmp(t.id.split('x-err-')[1]).focus();
163 }, this, {stopEvent:true}); // prevent anchor click navigation
169 showErrors : function(){
170 this.updateErrorList();
171 this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration: 300, easing:'easeOut'});
172 this.statusBar.setText(this.hideText);
173 this.formPanel.el.on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
177 hideErrors : function(){
178 var el = this.getMsgEl();
180 el.slideOut('b', {duration: 300, easing:'easeIn'});
181 this.statusBar.setText(this.showText);
183 this.formPanel.el.un('click', this.hideErrors, this);
187 onStatusClick : function(){
188 if(this.getMsgEl().isVisible()){
190 }else if(this.errors.getCount() > 0){