String.prototype.trim = function() { return this.replace(/^\s*/, "").replace(/\s*$/, ""); }; Array.prototype.insertBefore = function(idx, obj) { this.insertAfter(idx - 2, obj); } Array.prototype.insertAfter = function(idx, obj) { if(idx >= this.length) // insert index is out of bounds, add object to the end of the array this.push(obj); else { if(idx < 0) // insert index is negative, add object to the beginning of the array this.unshift(obj); else { var firstHalf = this.slice(0, idx + 1); var secondHalf = this.slice(idx + 1); firstHalf.push(obj); var i; var length = this.length; for(i = 0; i < length; i++) this.pop(); var result = firstHalf.concat(secondHalf); for(i = 0; i < result.length; i++) this.push(result[i]); } } }; Array.prototype.compare = function(testArr) { if (this.length != testArr.length) return false; for (var i = 0; i < testArr.length; i++) { if((this[i].compare && !this[i].compare(testArr[i])) || this[i] !== testArr[i]) return false; } return true; }; Ext.form.VTypes = function(){ // closure these in so they are only created once. var alpha = /^[a-zA-Z_]+$/; var alphanum = /^[a-zA-Z0-9_]+$/; var email = /^([\-\w]+)(\.[\w]+)*@([\w\-]+\.){1,5}([A-Za-z]){2,4}$/; var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i; // All these messages and functions are configurable return { 'email' : function(v){ return email.test(v); }, 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"', 'emailMask' : /[a-z0-9_\.\-@]/i, 'url' : function(v){ return url.test(v); }, 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"', 'alpha' : function(v) { return alpha.test(v); }, 'alphaText' : 'This field should only contain letters and _', 'alphaMask' : /[a-z_]/i, 'alphanum' : function(v){ return alphanum.test(v); }, 'alphanumText' : 'This field should only contain letters, numbers and _', 'alphanumMask' : /[a-z0-9_]/i }; }(); Ext.override(Ext.form.Field, { markInvalid : function(msg) { if(!this.rendered || this.preventMark) return; this.el.addClass(this.invalidClass); msg = msg || this.invalidText; switch(this.msgTarget) { case 'qtip': this.el.dom.qtip = msg; this.el.dom.qclass = 'x-form-invalid-tip'; if(Ext.QuickTips) Ext.QuickTips.enable(); break; case 'title': this.el.dom.title = msg; break; case 'under': if(!this.errorEl) { var elp = this.getErrorCt(); if(!elp) { this.el.dom.title = msg; break; } this.errorEl = elp.createChild({cls:'x-form-invalid-msg'}); // this.errorEl.setWidth(elp.getWidth(true)-20); } this.errorEl.update(msg); Ext.form.Field.msgFx[this.msgFx].show(this.errorEl, this); break; case 'side': if(!this.errorIcon) { var elp = this.getErrorCt(); if(!elp) { this.el.dom.title = msg; break; } this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'}); } this.alignErrorIcon(); this.errorIcon.dom.qtip = msg; this.errorIcon.dom.qclass = 'x-form-invalid-tip'; this.errorIcon.show(); this.on('resize', this.alignErrorIcon, this); break; default: var t = Ext.getDom(this.msgTarget); t.innerHTML = msg; t.style.display = this.msgDisplay; break; }; this.fireEvent('invalid', this, msg); } });