3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/*
\r
10 * Copyright(c) 2006-2008, Ext JS, LLC.
\r
11 * licensing@extjs.com
\r
13 * http://extjs.com/license
\r
16 <div id="cls-Ext.ux.ValidationStatus"></div>/**
17 * @class Ext.ux.ValidationStatus
18 * A {@link Ext.StatusBar} plugin that provides automatic error notification when the
19 * associated form contains validation errors.
20 * @extends Ext.Component
22 * Creates a new ValiationStatus plugin
23 * @param {Object} config A config object
25 Ext.ux.ValidationStatus = Ext.extend(Ext.Component, {
27 errorIconCls : 'x-status-error',
29 errorListCls : 'x-status-error-list',
31 validIconCls : 'x-status-valid',
33 showText : 'The form has errors (click for details...)',
35 hideText : 'Click again to hide the error list',
37 submitText : 'Saving...',
41 sb.on('render', function(){
44 this.errors = new Ext.util.MixedCollection();
45 this.listAlign = (sb.statusAlign=='right' ? 'br-tr?' : 'bl-tl?');
48 this.form = Ext.getCmp(this.form).getForm();
49 this.startMonitoring();
50 this.form.on('beforeaction', function(f, action){
51 if(action.type == 'submit'){
52 // Ignore monitoring while submitting otherwise the field validation
53 // events cause the status message to reset too early
57 var startMonitor = function(){
60 this.form.on('actioncomplete', startMonitor, this);
61 this.form.on('actionfailed', startMonitor, this);
63 }, this, {single:true});
\r
64 sb.on('afterlayout', function(){
\r
65 // Grab the statusEl after the first layout.
\r
66 sb.statusEl.getEl().on('click', this.onStatusClick, this, {buffer:200});
\r
67 }, this, {single: true});
71 startMonitoring : function(){
72 this.form.items.each(function(f){
73 f.on('invalid', this.onFieldValidation, this);
74 f.on('valid', this.onFieldValidation, this);
79 stopMonitoring : function(){
80 this.form.items.each(function(f){
81 f.un('invalid', this.onFieldValidation, this);
82 f.un('valid', this.onFieldValidation, this);
87 onDestroy : function(){
88 this.stopMonitoring();
89 this.statusBar.statusEl.un('click', this.onStatusClick, this);
90 Ext.ux.ValidationStatus.superclass.onDestroy.call(this);
94 onFieldValidation : function(f, msg){
99 this.errors.add(f.id, {field:f, msg:msg});
101 this.errors.removeKey(f.id);
103 this.updateErrorList();
104 if(this.errors.getCount() > 0){
105 if(this.statusBar.getText() != this.showText){
106 this.statusBar.setStatus({text:this.showText, iconCls:this.errorIconCls});
109 this.statusBar.clearStatus().setIcon(this.validIconCls);
114 updateErrorList : function(){
115 if(this.errors.getCount() > 0){
117 this.errors.each(function(err){
118 msg += ('<li id="x-err-'+ err.field.id +'"><a href="#">' + err.msg + '</a></li>');
120 this.getMsgEl().update(msg+'</ul>');
122 this.getMsgEl().update('');
127 getMsgEl : function(){
129 this.msgEl = Ext.DomHelper.append(Ext.getBody(), {
130 cls: this.errorListCls+' x-hide-offsets'
133 this.msgEl.on('click', function(e){
134 var t = e.getTarget('li', 10, true);
136 Ext.getCmp(t.id.split('x-err-')[1]).focus();
139 }, this, {stopEvent:true}); // prevent anchor click navigation
145 showErrors : function(){
146 this.updateErrorList();
147 this.getMsgEl().alignTo(this.statusBar.getEl(), this.listAlign).slideIn('b', {duration:.3, easing:'easeOut'});
148 this.statusBar.setText(this.hideText);
149 this.form.getEl().on('click', this.hideErrors, this, {single:true}); // hide if the user clicks directly into the form
153 hideErrors : function(){
154 var el = this.getMsgEl();
156 el.slideOut('b', {duration:.2, easing:'easeIn'});
157 this.statusBar.setText(this.showText);
159 this.form.getEl().un('click', this.hideErrors, this);
163 onStatusClick : function(){
164 if(this.getMsgEl().isVisible()){
166 }else if(this.errors.getCount() > 0){